git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* an hg-to-git adventure
@ 2007-03-27  9:43 Jim Meyering
  2007-03-27 11:33 ` Theodore Tso
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2007-03-27  9:43 UTC (permalink / raw
  To: git

Normally, converting a mercurial repository to git is simple: just
run the hg-to-git script (from git/contrib).  However, the one I did
yesterday was different.

Quick summary:

    I had to hack python not to barf on a delta involving .hg/hgrc,
    and to make hg-to-git work even when there are no files to commit.

Here are the details, in case someone else encounters the same problem.

The trouble with that particular hg repository is that the special file,
.hg/hgrc, is under version control.  Earlier versions of Mercurial allowed
that, but new ones do not, and part of the hg-to-git script runs "hg
update -C N" for each change-set number, N, and that "update" command
fails for any change set that includes a file in the .hg/ admin directory.

The very first change set adds just one file, .hg/hgrc.  Because
that file is in .hg/, "hg update -C 0" would fail with this diagnostic:

  "path contains illegal component: .hg/hgrc"

That looked easy to work around.  Just hack hg not to perform that check.
It turns out this approach is fine, since hg-to-git doesn't use the
explicit file list from mercurial, but rather simply git-commits all
changes brought in by the "hg update".  That means changes to .hg/*
admin files are ignored, which is perfect.  Here's the patch: (obviously,
intended solely for private, temporary use)

diff -r 0ce23256e454 mercurial/util.py
--- a/mercurial/util.py	Sat Mar 24 13:31:43 2007 +0100
+++ b/mercurial/util.py	Mon Mar 26 22:12:12 2007 +0200
@@ -652,10 +652,6 @@ def copyfiles(src, dst, hardlink=None):

 def audit_path(path):
     """Abort if path contains dangerous components"""
-    parts = os.path.normcase(path).split(os.sep)
-    if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '')
-        or os.pardir in parts):
-        raise Abort(_("path contains illegal component: %s\n") % path)

 def _makelock_file(info, pathname):
     ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)

To my surprise, that did not help.  I'd built and installed
mercurial into its own hierarchy with this command:

  python setup.py install --home=/p/p/hg-2007-03-26.20h24

then added /p/p/hg-2007-03-26.20h24/bin at the front of my PATH.
It turns out that the 2-line "hg" driver script was not using the
just-installed libraries.  So I changed /p/p/hg-2007-03-26.20h24/bin/hg,
inserting these two lines after the #! one:

  import sys
  sys.path.insert(0, "/p/p/hg-2007-03-26.20h24/lib/python")

[there's probably a way to do this with some PYTHON*
 envvar, but I prefer not to rely on envvar settings here ]

And that did the job, in that hg-to-git got past the initial failure.
However, it went only a few lines farther before failing anew, this
time because it tried to extract a substring (an SHA1 checksum) from the
empty string -- that happened because there were no files to git-commit
for that first change set.  The following patch works around that case:

diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index 37337ff..9fbc1d5 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -218,7 +218,10 @@ for cset in range(int(tip) + 1):

     # retrieve and record the version
     vvv = os.popen('git-show | head -1').read()
-    vvv = vvv[vvv.index(' ') + 1 : ].strip()
+    if vvv:
+        vvv = vvv[vvv.index(' ') + 1 : ].strip()
+    else:
+        vvv = '0';
     print 'record', cset, '->', vvv
     hgvers[str(cset)] = vvv

and once it got past that first change set, hg-to-git (using
the hacked "hg") converted the remaining 431 change sets.

FWIW, I also tried tailor, but it did no better than stock hg-to-git.
It might have worked with the hacked "hg", but I didn't try that.

Bottom line, I now have a git repo, and other conversions should be trivial.

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: an hg-to-git adventure
  2007-03-27  9:43 an hg-to-git adventure Jim Meyering
@ 2007-03-27 11:33 ` Theodore Tso
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Tso @ 2007-03-27 11:33 UTC (permalink / raw
  To: Jim Meyering; +Cc: git

On Tue, Mar 27, 2007 at 11:43:38AM +0200, Jim Meyering wrote:
> Normally, converting a mercurial repository to git is simple: just
> run the hg-to-git script (from git/contrib).  However, the one I did
> yesterday was different.

By the way, there is a faster hg-to-git script called hg-fast-export
located inside the fast-export repository:

	git://repo.or.cz/fast-export.git

This uses git-fast-import and does a much faster conversion job.  It
also has some features to clean up author names (including pulling out
Signed-Off-By: information so it can be stuffed into the author field)
automatically.

						- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-27 11:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-27  9:43 an hg-to-git adventure Jim Meyering
2007-03-27 11:33 ` Theodore Tso

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).