| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,9 +44,13 @@ Repo | |||
| 44 | 44 | of the active branch. | |
| 45 | 45 | * tree method now requires a Ref instance as input and defaults to the active_branche | |
| 46 | 46 | instead of master | |
| 47 | - * Removed 'log' method as it as effectively the same as the 'commits' method | ||
| 47 | + * Removed the following methods: | ||
| 48 | + - 'log' method as it as effectively the same as the 'commits' method | ||
| 49 | + - 'commits_since' as it is just a flag given to rev-list in Commit.iter_items | ||
| 50 | + - 'commit_count' as it was just a redirection to the respective commit method | ||
| 48 | 51 | * 'commits' method has no max-count of returned commits anymore, it now behaves | |
| 49 | 52 | like git-rev-list | |
| 53 | + | ||
| 50 | 54 | ||
| 51 | 55 | Diff | |
| 52 | 56 | ---- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,6 +223,21 @@ def transform_kwargs(self, **kwargs): | |||
| 223 | 223 | args.append("--%s=%s" % (dashify(k), v)) | |
| 224 | 224 | return args | |
| 225 | 225 | ||
| 226 | + @classmethod | ||
| 227 | + def __unpack_args(cls, arg_list): | ||
| 228 | + if not isinstance(arg_list, (list,tuple)): | ||
| 229 | + return [ str(arg_list) ] | ||
| 230 | + | ||
| 231 | + outlist = list() | ||
| 232 | + for arg in arg_list: | ||
| 233 | + if isinstance(arg_list, (list, tuple)): | ||
| 234 | + outlist.extend(cls.__unpack_args( arg )) | ||
| 235 | + # END recursion | ||
| 236 | + else: | ||
| 237 | + outlist.append(str(arg)) | ||
| 238 | + # END for each arg | ||
| 239 | + return outlist | ||
| 240 | + | ||
| 226 | 241 | def _call_process(self, method, *args, **kwargs): | |
| 227 | 242 | """ | |
| 228 | 243 | Run the given git command with the specified arguments and return | |
@@ -258,7 +273,8 @@ def _call_process(self, method, *args, **kwargs): | |||
| 258 | 273 | ||
| 259 | 274 | # Prepare the argument list | |
| 260 | 275 | opt_args = self.transform_kwargs(**kwargs) | |
| 261 | - ext_args = map(str, args) | ||
| 276 | + | ||
| 277 | + ext_args = self.__unpack_args(args) | ||
| 262 | 278 | args = opt_args + ext_args | |
| 263 | 279 | ||
| 264 | 280 | call = ["git", dashify(method)] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,7 +102,7 @@ def summary(self): | |||
| 102 | 102 | return self.message.split('\n', 1)[0] | |
| 103 | 103 | ||
| 104 | 104 | @classmethod | |
| 105 | - def count(cls, repo, ref, path=''): | ||
| 105 | + def count(cls, repo, ref, paths=''): | ||
| 106 | 106 | """ | |
| 107 | 107 | Count the number of commits reachable from this ref | |
| 108 | 108 | ||
@@ -112,16 +112,17 @@ def count(cls, repo, ref, path=''): | |||
| 112 | 112 | ``ref`` | |
| 113 | 113 | is the ref from which to begin (SHA1 or name) | |
| 114 | 114 | ||
| 115 | - ``path`` | ||
| 116 | - is an optinal path | ||
| 115 | + ``paths`` | ||
| 116 | + is an optinal path or a list of paths restricting the return value | ||
| 117 | + to commits actually containing the paths | ||
| 117 | 118 | ||
| 118 | 119 | Returns | |
| 119 | 120 | int | |
| 120 | 121 | """ | |
| 121 | - return len(repo.git.rev_list(ref, '--', path).strip().splitlines()) | ||
| 122 | + return len(repo.git.rev_list(ref, '--', paths).strip().splitlines()) | ||
| 122 | 123 | ||
| 123 | 124 | @classmethod | |
| 124 | - def iter_items(cls, repo, ref, path='', **kwargs): | ||
| 125 | + def iter_items(cls, repo, ref, paths='', **kwargs): | ||
| 125 | 126 | """ | |
| 126 | 127 | Find all commits matching the given criteria. | |
| 127 | 128 | ||
@@ -131,14 +132,15 @@ def iter_items(cls, repo, ref, path='', **kwargs): | |||
| 131 | 132 | ``ref`` | |
| 132 | 133 | is the ref from which to begin (SHA1, Head or name) | |
| 133 | 134 | ||
| 134 | - ``path`` | ||
| 135 | - is an optinal path, if set only Commits that include the path | ||
| 136 | - will be considered | ||
| 135 | + ``paths`` | ||
| 136 | + is an optinal path or list of paths, if set only Commits that include the path | ||
| 137 | + or paths will be considered | ||
| 137 | 138 | ||
| 138 | 139 | ``kwargs`` | |
| 139 | - optional keyword arguments to git where | ||
| 140 | + optional keyword arguments to git rev-list where | ||
| 140 | 141 | ``max_count`` is the maximum number of commits to fetch | |
| 141 | 142 | ``skip`` is the number of commits to skip | |
| 143 | + ``since`` all commits since i.e. '1970-01-01' | ||
| 142 | 144 | ||
| 143 | 145 | Returns | |
| 144 | 146 | iterator yielding Commit items | |
@@ -147,7 +149,7 @@ def iter_items(cls, repo, ref, path='', **kwargs): | |||
| 147 | 149 | options.update(kwargs) | |
| 148 | 150 | ||
| 149 | 151 | # the test system might confront us with string values - | |
| 150 | - proc = repo.git.rev_list(ref, '--', path, **options) | ||
| 152 | + proc = repo.git.rev_list(ref, '--', paths, **options) | ||
| 151 | 153 | return cls._iter_from_process_or_stream(repo, proc) | |
| 152 | 154 | ||
| 153 | 155 | @classmethod | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,17 +116,20 @@ def tags(self): | |||
| 116 | 116 | """ | |
| 117 | 117 | return Tag.list_items(self) | |
| 118 | 118 | ||
| 119 | - def blame(self, commit, file): | ||
| 119 | + def blame(self, ref, file): | ||
| 120 | 120 | """ | |
| 121 | - The blame information for the given file at the given commit | ||
| 121 | + The blame information for the given file at the given ref. | ||
| 122 | + | ||
| 123 | + ``ref`` | ||
| 124 | + Ref object or Commit | ||
| 122 | 125 | ||
| 123 | 126 | Returns | |
| 124 | 127 | list: [git.Commit, list: [<line>]] | |
| 125 | 128 | A list of tuples associating a Commit object with a list of lines that | |
| 126 | 129 | changed within the given commit. The Commit objects will be given in order | |
| 127 | 130 | of appearance. | |
| 128 | 131 | """ | |
| 129 | - data = self.git.blame(commit, '--', file, p=True) | ||
| 132 | + data = self.git.blame(ref, '--', file, p=True) | ||
| 130 | 133 | commits = {} | |
| 131 | 134 | blames = [] | |
| 132 | 135 | info = None | |
@@ -196,17 +199,17 @@ def blame(self, commit, file): | |||
| 196 | 199 | # END distinguish hexsha vs other information | |
| 197 | 200 | return blames | |
| 198 | 201 | ||
| 199 | - def commits(self, start=None, path='', max_count=None, skip=0): | ||
| 202 | + def commits(self, start=None, paths='', max_count=None, skip=0): | ||
| 200 | 203 | """ | |
| 201 | 204 | A list of Commit objects representing the history of a given ref/commit | |
| 202 | 205 | ||
| 203 | 206 | ``start`` | |
| 204 | - is a ref to start the commits from. If start is None, | ||
| 207 | + is a Ref or Commit to start the commits from. If start is None, | ||
| 205 | 208 | the active branch will be used | |
| 206 | 209 | ||
| 207 | - ``path`` | ||
| 208 | - is an optional path to limit the returned commits to | ||
| 209 | - Commits that do not contain that path will not be returned. | ||
| 210 | + ``paths`` | ||
| 211 | + is an optional path or a list of paths to limit the returned commits to | ||
| 212 | + Commits that do not contain that path or the paths will not be returned. | ||
| 210 | 213 | ||
| 211 | 214 | ``max_count`` | |
| 212 | 215 | is the maximum number of commits to return (default None) | |
@@ -225,63 +228,27 @@ def commits(self, start=None, path='', max_count=None, skip=0): | |||
| 225 | 228 | options.pop('max_count') | |
| 226 | 229 | if start is None: | |
| 227 | 230 | start = self.active_branch | |
| 228 | - return Commit.list_items(self, start, path, **options) | ||
| 231 | + | ||
| 232 | + return Commit.list_items(self, start, paths, **options) | ||
| 229 | 233 | ||
| 230 | - def commits_between(self, frm, to): | ||
| 234 | + def commits_between(self, frm, to, *args, **kwargs): | ||
| 231 | 235 | """ | |
| 232 | 236 | The Commits objects that are reachable via ``to`` but not via ``frm`` | |
| 233 | 237 | Commits are returned in chronological order. | |
| 234 | 238 | ||
| 235 | 239 | ``from`` | |
| 236 | - is the branch/commit name of the younger item | ||
| 240 | + is the Ref/Commit name of the younger item | ||
| 237 | 241 | ||
| 238 | 242 | ``to`` | |
| 239 | - is the branch/commit name of the older item | ||
| 243 | + is the Ref/Commit name of the older item | ||
| 240 | 244 | ||
| 241 | 245 | Returns | |
| 242 | 246 | ``git.Commit[]`` | |
| 243 | 247 | """ | |
| 244 | 248 | return reversed(Commit.list_items(self, "%s..%s" % (frm, to))) | |
| 245 | 249 | ||
| 246 | - def commits_since(self, start='master', path='', since='1970-01-01'): | ||
| 247 | - """ | ||
| 248 | - The Commits objects that are newer than the specified date. | ||
| 249 | - Commits are returned in chronological order. | ||
| 250 | - | ||
| 251 | - ``start`` | ||
| 252 | - is the branch/commit name (default 'master') | ||
| 253 | - | ||
| 254 | - ``path`` | ||
| 255 | - is an optinal path to limit the returned commits to. | ||
| 256 | - | ||
| 257 | - | ||
| 258 | - ``since`` | ||
| 259 | - is a string represeting a date/time | ||
| 260 | - | ||
| 261 | - Returns | ||
| 262 | - ``git.Commit[]`` | ||
| 263 | - """ | ||
| 264 | - options = {'since': since} | ||
| 265 | - | ||
| 266 | - return Commit.list_items(self, start, path, **options) | ||
| 267 | 250 | ||
| 268 | - def commit_count(self, start='master', path=''): | ||
| 269 | - """ | ||
| 270 | - The number of commits reachable by the given branch/commit | ||
| 271 | - | ||
| 272 | - ``start`` | ||
| 273 | - is the branch/commit name (default 'master') | ||
| 274 | - | ||
| 275 | - ``path`` | ||
| 276 | - is an optional path | ||
| 277 | - Commits that do not contain the path will not contribute to the count. | ||
| 278 | - | ||
| 279 | - Returns | ||
| 280 | - ``int`` | ||
| 281 | - """ | ||
| 282 | - return Commit.count(self, start, path) | ||
| 283 | - | ||
| 284 | - def commit(self, id=None, path = ''): | ||
| 251 | + def commit(self, id=None, paths = ''): | ||
| 285 | 252 | """ | |
| 286 | 253 | The Commit object for the specified id | |
| 287 | 254 | ||
@@ -290,8 +257,9 @@ def commit(self, id=None, path = ''): | |||
| 290 | 257 | if None, it defaults to the active branch | |
| 291 | 258 | ||
| 292 | 259 | ||
| 293 | - ``path`` | ||
| 294 | - is an optional path, if set the returned commit must contain the path. | ||
| 260 | + ``paths`` | ||
| 261 | + is an optional path or a list of paths, | ||
| 262 | + if set the returned commit must contain the path or paths | ||
| 295 | 263 | ||
| 296 | 264 | Returns | |
| 297 | 265 | ``git.Commit`` | |
@@ -300,7 +268,7 @@ def commit(self, id=None, path = ''): | |||
| 300 | 268 | id = self.active_branch | |
| 301 | 269 | options = {'max_count': 1} | |
| 302 | 270 | ||
| 303 | - commits = Commit.list_items(self, id, path, **options) | ||
| 271 | + commits = Commit.list_items(self, id, paths, **options) | ||
| 304 | 272 | ||
| 305 | 273 | if not commits: | |
| 306 | 274 | raise ValueError, "Invalid identifier %s, or given path '%s' too restrictive" % ( id, path ) | |
@@ -317,7 +285,7 @@ def commit_deltas_from(self, other_repo, ref='master', other_ref='master'): | |||
| 317 | 285 | other_repo_refs = other_repo.git.rev_list(other_ref, '--').strip().splitlines() | |
| 318 | 286 | ||
| 319 | 287 | diff_refs = list(set(other_repo_refs) - set(repo_refs)) | |
| 320 | - return map(lambda ref: Commit.list_items(other_repo, ref, max_count=1)[0], diff_refs) | ||
| 288 | + return map(lambda ref: Commit(other_repo, ref ), diff_refs) | ||
| 321 | 289 | ||
| 322 | 290 | def tree(self, treeish=None): | |
| 323 | 291 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -215,6 +215,9 @@ def test_rev_list_bisect_all(self, git): | |||
| 215 | 215 | for sha1, commit in zip(expected_ids, commits): | |
| 216 | 216 | assert_equal(sha1, commit.id) | |
| 217 | 217 | ||
| 218 | + def test_count(self): | ||
| 219 | + assert Commit.count( self.repo, '0.1.5' ) == 141 | ||
| 220 | + | ||
| 218 | 221 | def test_str(self): | |
| 219 | 222 | commit = Commit(self.repo, id='abc') | |
| 220 | 223 | assert_equal ("abc", str(commit)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,15 +65,6 @@ def test_commits(self, git): | |||
| 65 | 65 | ||
| 66 | 66 | assert_true(git.called) | |
| 67 | 67 | ||
| 68 | - @patch_object(Git, '_call_process') | ||
| 69 | - def test_commit_count(self, git): | ||
| 70 | - git.return_value = fixture('rev_list_count') | ||
| 71 | - | ||
| 72 | - assert_equal(655, self.repo.commit_count('master')) | ||
| 73 | - | ||
| 74 | - assert_true(git.called) | ||
| 75 | - assert_equal(git.call_args, (('rev_list', 'master', '--', ''), {})) | ||
| 76 | - | ||
| 77 | 68 | @patch_object(Git, '_call_process') | |
| 78 | 69 | def test_commit(self, git): | |
| 79 | 70 | git.return_value = ListProcessAdapter(fixture('rev_list_single')) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments