Commits

Mike Bayer committed 35e2813

- 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

Comments (0)

Files changed (1)

hggit/git_handler.py

 
         self.paths = ui.configitems('paths')
 
+        self.branch_bookmark_suffix = ui.config('git', 'branch_bookmark_suffix')
+
         self.load_map()
         self.load_tags()
 
         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]
                 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 {}
 
                 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/')])
 
                     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)