[PATCH] repo-convert: Convert current git branch into hg named branch

Rocco Rutte pdmef at gmx.net
Thu Mar 15 09:59:00 CDT 2007


We now simply parse the output of git-branch(1) to get the current
branch and use it for for the commit() function.

This patch also uses git-rev-parse(1) with that branch name instead of
HEAD as preparation to allow specifying the source branch via command
line since there's no technical reason to have it checkout out on the
git side.
---
 Note: please CC me in any replies as I'm not subscribed to the list.

 contrib/convert-repo |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/contrib/convert-repo b/contrib/convert-repo
index 6fd189e..6b6b672 100755
--- a/contrib/convert-repo
+++ b/contrib/convert-repo
@@ -296,8 +296,16 @@ class convert_git:
         if not os.path.exists(path + "/objects"):
             raise NoRepo("couldn't open GIT repo %s" % path)
 
+        fh = os.popen("GIT_DIR=%s git-branch" % self.path)
+        self.branch = 'master'
+        for branch in fh.readlines():
+          if branch[0] == '*':
+            self.branch = branch[2:-1]
+
+        status("importing git branch '%s'...\n" % self.branch)
+
     def getheads(self):
-        fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path)
+        fh = os.popen("GIT_DIR=%s git-rev-parse --verify %s" % (self.path, self.branch))
         return [fh.read()[:-1]]
 
     def catfile(self, rev, type):
@@ -355,7 +363,7 @@ class convert_git:
         tz = -int(tzs) * (int(tzh) * 3600 + int(tzm))
         date = tm + " " + str(tz)
 
-        c = commit(parents=parents, date=date, author=author, desc=message)
+        c = commit(parents=parents, date=date, author=author, desc=message, branch=self.branch)
         return c
 
     def gettags(self):
-- 
1.5.0.3.920.g51d7f



More information about the Mercurial-devel mailing list