diff options
Diffstat (limited to 'lib/git/commit.py')
-rw-r--r-- | lib/git/commit.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py index 057530a6..091cf78c 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -41,7 +41,7 @@ class Commit(LazyMixin): is the committed DateTime ``message`` - is the first line of the commit message + is the commit message ``parents`` is the list of the parents of the commit @@ -81,8 +81,12 @@ class Commit(LazyMixin): def id_abbrev(self): return self.id[0:7] + @property + def summary(self): + return self.message.split('\n', 1)[0] + @classmethod - def count(cls, repo, ref): + def count(cls, repo, ref, path=''): """ Count the number of commits reachable from this ref @@ -92,13 +96,16 @@ class Commit(LazyMixin): ``ref`` is the ref from which to begin (SHA1 or name) + ``path`` + is an optinal path + Returns int """ - return len(repo.git.rev_list(ref).strip().splitlines()) + return len(repo.git.rev_list(ref, '--', path).strip().splitlines()) @classmethod - def find_all(cls, repo, ref, **kwargs): + def find_all(cls, repo, ref, path='', **kwargs): """ Find all commits matching the given criteria. ``repo`` @@ -107,6 +114,9 @@ class Commit(LazyMixin): ``ref`` is the ref from which to begin (SHA1 or name) + ``path`` + is an optinal path + ``options`` is a Hash of optional arguments to git where ``max_count`` is the maximum number of commits to fetch @@ -118,7 +128,7 @@ class Commit(LazyMixin): options = {'pretty': 'raw'} options.update(kwargs) - output = repo.git.rev_list(ref, **options) + output = repo.git.rev_list(ref, '--', path, **options) return cls.list_from_string(repo, output) @classmethod @@ -153,7 +163,7 @@ class Commit(LazyMixin): while lines and lines[0].startswith(' '): messages.append(lines.pop(0).strip()) - message = messages and messages[0] or '' + message = '\n'.join(messages) commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date, committer=committer, committed_date=committed_date, message=message)) @@ -194,13 +204,13 @@ class Commit(LazyMixin): if b: paths.insert(0, b) paths.insert(0, a) - text = repo.git.diff(full_index=True, *paths) + text = repo.git.diff('-M', full_index=True, *paths) return diff.Diff.list_from_string(repo, text) @property def diffs(self): if not self.parents: - d = self.repo.git.show(self.id, full_index=True, pretty='raw') + d = self.repo.git.show(self.id, '-M', full_index=True, pretty='raw') if re.search(r'diff --git a', d): if not re.search(r'^diff --git a', d): p = re.compile(r'.+?(diff --git a)', re.MULTILINE | re.DOTALL) @@ -214,14 +224,14 @@ class Commit(LazyMixin): @property def stats(self): if not self.parents: - text = self.repo.git.diff(self.id, numstat=True) + text = self.repo.git.diff(self.id, '--', numstat=True) text2 = "" for line in text.splitlines(): (insertions, deletions, filename) = line.split("\t") text2 += "%s\t%s\t%s\n" % (deletions, insertions, filename) text = text2 else: - text = self.repo.git.diff(self.parents[0].id, self.id, numstat=True) + text = self.repo.git.diff(self.parents[0].id, self.id, '--', numstat=True) return stats.Stats.list_from_string(self.repo, text) def __str__(self): |