Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement GitChangeset.get_branches()

This results in branch annotations in the timeline view.

For now, GitChangeset.get_branches() returns all the branches the
given changeset is on, or to quote the `git branch` man-page: "In
other words, the branches whose tip commits are descendants of the
named commit."
  • Loading branch information...
commit fc6bf2c5d020cd032a8f97691ebc8904a497a6ff 1 parent 8ec5adf
@hvr authored
Showing with 27 additions and 1 deletion.
  1. +19 −0 tracext/git/PyGIT.py
  2. +8 −1 tracext/git/git_fs.py
View
19 tracext/git/PyGIT.py
@@ -420,6 +420,25 @@ def oldest_rev(self):
def youngest_rev(self):
return self.rev_cache.youngest_rev
+ def get_branch_contains(self, sha, resolve=False):
+ """
+ return list of reachable head sha ids or (names, sha) pairs if resolve is true
+
+ see also get_branches()
+ """
+
+ _rev_cache = self.rev_cache
+
+ try:
+ rheads = _rev_cache.rev_dict[sha][3]
+ except KeyError:
+ return []
+
+ if resolve:
+ return [ (k, v) for k, v in _rev_cache.branch_dict if v in rheads ]
+
+ return rheads
+
def history_relative_rev(self, sha, rel_pos):
db = self.get_commits()
View
9 tracext/git/git_fs.py
@@ -537,11 +537,11 @@ class GitChangeset(Changeset):
} # TODO: U, X, B
def __init__(self, repos, sha):
- self.repos = repos
try:
msg, props = repos.git.read_commit(sha)
except PyGIT.GitErrorSha:
raise NoSuchChangeset(sha)
+
self.props = props
assert 'children' not in props
@@ -606,3 +606,10 @@ def get_changes(self):
paths_seen.add(path)
yield (to_unicode(path), kind, action, to_unicode(p_path), p_rev)
+
+
+ def get_branches(self):
+ _rev = self.rev
+
+ return [ (k, v == _rev)
+ for k, v in self.repos.git.get_branch_contains(_rev, resolve=True) ]
Please sign in to comment.
Something went wrong with that request. Please try again.