[PATCH] Updated convert-repo script (1/3 Git 1.3.0 fix)

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun May 14 21:25:07 CDT 2006


Thus spake Thomas Arendsen Hein:
> * Sébastien Pierre <sebastien at xprima.com> [20060502 21:39]:
> >      def getheads(self):
> > -        return [file(self.path + "/HEAD").read()[:-1]]
> > +        # On some versions of git, the HEAD file last line is like
> > +        # ref: refs/heads/master
> > +        # And we only want "master" here
> > +        head = file(self.path + "/HEAD").read()[:-1]
> > +        head = head.split("/")[-1]
> > +        return [head]
> >  
> >      def catfile(self, rev, type):
> >          if rev == "0" * 40: raise IOError()
> 
> Can anyone confirm that this works with old and new git versions?
> Then it can be pushed.

This one wouldn't really work - getheads would usually return something
like ['master'], and convert-repo would end up writing a line in the map
file mapping "master" to the hash number of some converted hg revision.
(This would also affect my "just return ['HEAD']" suggestion)

This would work fine for the initial conversion, but the following
incremental conversions would fail (since it would think the revision
"master" was already converted).

The patch below was tested with the git repository using a pre-historic
git from last July, an ancient git from the end of last September (right
after symbolic refs were introduced) and current git, both with HEAD
being a symlink and HEAD being a symbolic ref (when supported).

In all cases the results were identical to current convert-repo using a
symlink for HEAD.

Alexis

# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Node ID aa14f7a6126d5c392c0bad4a1099e4991573e230
# Parent  09ed44225571cf4fc05fac6388198542c03086c7
make convert-repo deal with git symbolic refs.

Problem noticed by Sébastien Pierre

diff -r 09ed44225571 -r aa14f7a6126d contrib/convert-repo
--- a/contrib/convert-repo	Sun May 14 18:24:32 2006 +0200
+++ b/contrib/convert-repo	Sun May 14 21:24:04 2006 -0300
@@ -28,7 +28,8 @@ class convert_git:
         self.path = path
 
     def getheads(self):
-        return [file(self.path + "/HEAD").read()[:-1]]
+        fh = os.popen("GIT_DIR=%s git-rev-parse --verify HEAD" % self.path)
+        return [fh.read()[:-1]]
 
     def catfile(self, rev, type):
         if rev == "0" * 40: raise IOError()


More information about the Mercurial mailing list