changeset 441:35e2813f58a5

- add "branch_bookmark_names" parameter. this allows bookmarks that mimic a branchname to be maintained on the git side without a particular suffix - e.g. if the hg repo had a branch "release_05", and a bookmark created onto it "release_05_bookmark", the branch on the git side would be named "release_05". When pulling branches back from git, if an hg named branch of that name exists, the suffix is appended back onto the name before creating a bookmark on the hg side. This is strictly so that a git repo can be generated that has the same "branch names" as an older hg repo that has named branches, and has had bookmarks added in to mirror the branch names. This is given the restrictions that A. hg named branches can never be renamed and B. hg-git only supports hg bookmarks, not branches
author Mike Bayer <mike_mp@zzzcomputing.com>
date Sun, 18 Dec 2011 18:54:16 -0500
parents 32afa497834d
children 553dd7078058
files hggit/git_handler.py
diffstat 1 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Fri Nov 11 16:25:56 2011 +0100
+++ b/hggit/git_handler.py	Sun Dec 18 18:54:16 2011 -0500
@@ -82,6 +82,8 @@
 
         self.paths = ui.configitems('paths')
 
+        self.branch_bookmark_suffix = ui.config('git', 'branch_bookmark_suffix')
+
         self.load_map()
         self.load_tags()
 
@@ -721,7 +723,10 @@
         for rev in revs:
             ctx = self.repo[rev]
             if getattr(ctx, 'bookmarks', None):
-                labels = lambda c: ctx.tags() + ctx.bookmarks()
+                labels = lambda c: ctx.tags() + [
+                                fltr for fltr, bm 
+                                in self._filter_for_bookmarks(ctx.bookmarks())
+                            ]
             else:
                 labels = lambda c: ctx.tags()
             prep = lambda itr: [i.replace(' ', '_') for i in itr]
@@ -839,13 +844,25 @@
                 self.git.refs['refs/tags/' + tag] = self.map_git_get(hex(sha))
                 self.tags[tag] = hex(sha)
 
+    def _filter_for_bookmarks(self, bms):
+        if not self.branch_bookmark_suffix:
+            return [(bm, bm) for bm in bms]
+        else:
+            def _filter_bm(bm):
+                if bm.endswith(self.branch_bookmark_suffix):
+                    return bm[0:-(len(self.branch_bookmark_suffix))]
+                else:
+                    return bm
+            return [(_filter_bm(bm), bm) for bm in bms]
+
     def local_heads(self):
         try:
             if getattr(bookmarks, 'parse', None):
                 bms = bookmarks.parse(self.repo)
             else:
                 bms = self.repo._bookmarks
-            return dict([(bm, hex(bms[bm])) for bm in bms])
+            return dict([(filtered_bm, hex(bms[bm])) for 
+                        filtered_bm, bm in self._filter_for_bookmarks(bms)])
         except AttributeError: #pragma: no cover
             return {}
 
@@ -886,6 +903,7 @@
                 bms = bookmarks.parse(self.repo)
             else:
                 bms = self.repo._bookmarks
+
             heads = dict([(ref[11:],refs[ref]) for ref in refs
                           if ref.startswith('refs/heads/')])
 
@@ -903,6 +921,22 @@
                     if bm.ancestor(self.repo[hgsha]) == bm:
                         # fast forward
                         bms[head] = hgsha
+
+            # if there's a branch bookmark suffix,
+            # then add it on to all bookmark names
+            # that would otherwise conflict with a branch
+            # name
+            if self.branch_bookmark_suffix:
+                real_branch_names = self.repo.branchmap()
+                bms = dict(
+                    (
+                        bm_name + self.branch_bookmark_suffix 
+                            if bm_name in real_branch_names
+                        else bm_name,
+                        bms[bm_name]
+                    )
+                    for bm_name in bms
+                )
             if heads:
                 if oldbm:
                     bookmarks.write(self.repo, bms)