changeset 124:9dafb9ac24ff

hg bookmarks to local git branches
author Ian Dees <undees@gmail.com>
date Sun, 17 May 2009 14:50:50 -0700
parents b51381c6fab8
children 5b702bbf078f
files git_handler.py
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/git_handler.py	Sun May 17 01:55:48 2009 -0700
+++ b/git_handler.py	Sun May 17 14:50:50 2009 -0700
@@ -154,7 +154,23 @@
         return self._config['remote.' + remote_name + '.url']
 
     def update_references(self):
-        # TODO : if bookmarks exist, add them as git branches
+        try:
+            # We only care about bookmarks of the form 'name',
+            # not 'remote/name'.
+            def is_local_ref(item): return item[0].count('/') == 0
+            bms = bookmarks.parse(self.repo)
+            bms = dict(filter(is_local_ref, bms.items()))
+
+            # Create a local Git branch name for each
+            # Mercurial bookmark.
+            for key in bms:
+                hg_sha  = hex(bms[key])
+                git_sha = self.map_git_get(hg_sha)
+                self.git.set_ref('refs/heads/' + key, git_sha)
+        except AttributeError:
+            # No bookmarks extension
+            pass
+
         c = self.map_git_get(hex(self.repo.changelog.tip()))
         self.git.set_ref('refs/heads/master', c)