SourceForge: tortoisehg/tortoisehg: changeset 3864:2f94a4b0f975
logview: Make BranchGrapher respect branch name.
authorPeer Sommerlund <peso@users.sourceforge.net>
Mon Sep 07 14:19:01 2009 +0200 (2 months ago)
changeset 38642f94a4b0f975
parent 3863a6b988002839
child 387029c0ed7594c4
logview: Make BranchGrapher respect branch name.

BranchGrapher treats the change-graph as a set of paths,
where each path represents a branch. This change prevents
paths that span multiple named branches, and instead tries
to follow the branch name as far back as possible.
hggtk/logview/revgraph.py
     1.1 --- a/hggtk/logview/revgraph.py	Mon Sep 07 13:33:42 2009 +0900
     1.2 +++ b/hggtk/logview/revgraph.py	Mon Sep 07 14:19:01 2009 +0200
     1.3 @@ -179,9 +179,12 @@
     1.4          #
     1.5          #  Graph variables
     1.6          #  These hold information related to the graph. Most are computed lazily.
     1.7 +        #  The graph is split into a number of "branches", defined as paths within
     1.8 +        #  a named branch.
     1.9          #
    1.10          
    1.11 -        # Map rev to next rev in branch = first parent of rev. 
    1.12 +        # Map rev to next rev in branch = parent with same branch name
    1.13 +        # If two parents, use first that has same branch name.
    1.14          # The parent of last rev in a branch is undefined, 
    1.15          # even if the revsion has a parent rev.
    1.16          self.parent_of = {}
    1.17 @@ -202,6 +205,9 @@
    1.18      def _get_parents(self, rev):
    1.19          return [x for x in self.repo.changelog.parentrevs(rev) if x != nullrev]
    1.20          
    1.21 +    def _branch_name(self, rev):
    1.22 +        return self.repo[rev].branch()
    1.23 +        
    1.24      def _covered_rev(self, rev):
    1.25          """True if rev is inside the revision range for the iterator"""
    1.26          return self.stop_rev <= rev
    1.27 @@ -215,22 +221,26 @@
    1.28          self.color4branch[branch_head] = self.nextcolor
    1.29          self.nextcolor += 1
    1.30          self.next_in_branch[branch_head] = branch_head
    1.31 +        branch_name = self._branch_name(branch_head)
    1.32          rev = branch_head
    1.33          while not rev in self.branch4rev:
    1.34 -            # TODO consider lazy evaluation here
    1.35 +            # Determine if rev should be used
    1.36              if not self._covered_rev(rev):
    1.37                  # rev is outside visible range, so we don't know tail location
    1.38                  self.branch_tail[branch_head] = 0 # Prev revs wasn't tail
    1.39                  return
    1.40 +            # Add rev to branch
    1.41              self.branch4rev[rev] = branch_head
    1.42              self.branch_tail[branch_head] = rev
    1.43 -            parents = self._get_parents(rev)
    1.44 -            if not parents:
    1.45 -                # All revisions have been exhausted (rev = 0)
    1.46 -                self.parent_of[rev] = None
    1.47 +            # Find next revision in branch
    1.48 +            self.parent_of[rev] = None
    1.49 +            for parent in self._get_parents(rev):
    1.50 +                if self._branch_name(parent) == branch_name:
    1.51 +                    self.parent_of[rev] = parent
    1.52 +                    break
    1.53 +            if self.parent_of[rev] is None:
    1.54                  return
    1.55 -            self.parent_of[rev] = parents[0]
    1.56 -            rev = parents[0]
    1.57 +            rev = self.parent_of[rev]
    1.58  
    1.59      def _get_rev_branch(self, rev):
    1.60          """Find revision branch or create a new branch"""