mercurial --> plain text --> mercurial

Matt Mackall mpm at selenic.com
Thu Mar 27 11:09:25 CDT 2008


On Thu, 2008-03-27 at 14:24 +0000, didier deshommes wrote:
> Hi everyone,
> Sage (http://www.sagemath.org/) uses hg for its source control and recently a
> question has come up about the possibility of doing the following:
> 
>  (1) export everything in the .hg repo to something (perhaps a ton of
> stuff) in plain text format,
>  (2) delete .hg/ directory
>  (3) do something that recovers the .hg/ directory from the output of (1).

This will work for the export side:

#!/usr/bin/env python
import sys
from mercurial import revlog, node

for f in sys.argv[1:]:
    r = revlog.revlog(open, f)
    print "file:", f
    for i in xrange(r.count()):
        n = r.node(i)
        p = r.parents(i)
        d = r.revision(n)
        print "node:", node.hex(n)
        print "linkrev:", r.linkrev(n)
        print "parents:", node.hex(p[0]), node.hex(p[1])
        print "length:", len(d)
        print "-start-"
        print d
        print "-end-"

Then you can do something like:

find .hg/store -name "*.i" | xargs ./dumprevlog > repo.dump 

This will make a nice flat, uncompressed file with everything you need
to reconstruct a repo. But it'll be huge. The mercurial repo goes from
11MB to 435MB. Other projects will get -much- bigger; I've seen large
revlogs with compression ratios of > 1000:1.

I'm too busy to write the import side of this today, but it'll be about
as long. And you shouldn't actually need that piece if you only need to
scan the dump.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial mailing list