contrib/convert-repo
author Thomas Arendsen Hein <thomas@intevation.de>
Tue, 14 Jun 2005 08:49:52 +0100
changeset 348 442eb02cf870
parent 316 c48d069163d6
child 431 dfc44f3f587c
permissions -rwxr-xr-x
Improved hgeditor: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Improved hgeditor: hgeditor now uses $EDITOR and sets options according to emacs/vim/... Cleanup of temporary files. Use simple 'hg diff' instead of calling it for every file. Call gpg only if commit message was changed. manifest hash: 5c56bf580f9c2ef2a7d8b680bfb73fdd3b232044 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCrowgW7P1GVgWeRoRApiOAJ0UI9/OY3yr4bv0no+KCcponSq+ZwCdFDUU No8t9ni6/72zmlcpB13E63A= =oSyb -----END PGP SIGNATURE-----
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     1
#!/usr/bin/env python
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     2
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     3
# This is a generalized framework for converting between SCM
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     4
# repository formats.
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     5
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     6
# In its current form, it's hardcoded to convert incrementally between
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     7
# git and Mercurial.
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     8
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
     9
# To use, you must first import the first git version into Mercurial,
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    10
# and establish a mapping between the git commit hash and the hash in
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    11
# Mercurial for that version. This mapping is kept in a simple text
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    12
# file with lines like so:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    13
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    14
# <git hash> <mercurial hash>
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    15
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    16
# To convert the rest of the repo, run:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    17
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    18
# convert-repo <git-dir> <hg-dir> <mapfile>
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    19
#
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    20
# This updates the mapfile on each commit copied, so it can be
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    21
# interrupted and can be run repeatedly to copy new commits.
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    22
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    23
import sys, os, zlib, sha
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    24
from mercurial import hg, ui
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    25
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    26
class convert_git:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    27
    def __init__(self, path):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    28
        self.path = path
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    29
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    30
    def getheads(self):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    31
        h = file(self.path + "/.git/HEAD").read()[:-1]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    32
        return [h]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    33
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    34
    def getfile(self, name, rev):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    35
        a = file(self.path + ("/.git/objects/%s/%s"
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    36
                              % (rev[:2], rev[2:]))).read()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    37
        b = zlib.decompress(a)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    38
        if sha.sha(b).hexdigest() != rev: raise "bad hash"
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    39
        head, text = b.split('\0', 1)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    40
        return text
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    41
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    42
    def getchanges(self, version):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    43
        path = os.getcwd()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    44
        os.chdir(self.path)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    45
        fh = os.popen("git-diff-tree -m -r %s" % (version))
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    46
        os.chdir(path)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    47
        
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    48
        changes = []
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    49
        for l in fh:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    50
            if "\t" not in l: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    51
            m, f = l[:-1].split("\t")
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    52
            m = m.split()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    53
            h = m[3]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    54
            p = (m[1] == "100755")
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    55
            changes.append((f, h, p))
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    56
        return changes
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    57
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    58
    def getcommit(self, version):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    59
        c = self.getfile("", version) # read the commit hash
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    60
        end = c.find("\n\n")
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    61
        message = c[end+2:]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    62
        l = c[:end].splitlines()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    63
        manifest = l[0].split()[1]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    64
        parents = []
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    65
        for e in l[1:]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    66
            n,v = e.split(" ", 1)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    67
            if n == "author":
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    68
                p = v.split()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    69
                date = " ".join(p[-2:])
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    70
                author = " ".join(p[:-2])
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    71
                if author[0] == "<": author = author[1:-1]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    72
            if n == "parent": parents.append(v)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    73
        return (parents, author, date, message)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    74
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    75
class convert_mercurial:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    76
    def __init__(self, path):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    77
        self.path = path
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    78
        u = ui.ui()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    79
        self.repo = hg.repository(u, path)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    80
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    81
    def getheads(self):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    82
        h = self.repo.changelog.heads()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    83
        h = [ hg.hex(x) for x in h ]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    84
        return h
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    85
        
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    86
    def putfile(self, f, e, data):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    87
        self.repo.wfile(f, "w").write(data)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    88
        hg.set_exec(self.repo.wjoin(f), e)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    89
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    90
    def delfile(self, f):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    91
        try:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    92
            os.unlink(self.repo.wjoin(f))
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    93
            self.repo.remove([f])
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    94
        except:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    95
            pass
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    96
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    97
    def putcommit(self, files, parents, author, dest, text):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    98
        p1, p2 = "0"*40, "0"*40
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    99
        if len(parents) > 0: p1 = parents[0]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   100
        if len(parents) > 1: p2 = parents[1]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   101
        if len(parents) > 2: raise "the dreaded octopus merge!"
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   102
        self.repo.rawcommit(files, text, author, dest, 
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   103
                            hg.bin(p1), hg.bin(p2))
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   104
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   105
        return hg.hex(self.repo.changelog.tip())
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   106
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   107
class convert:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   108
    def __init__(self, source, dest, mapfile):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   109
        self.source = source
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   110
        self.dest = dest
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   111
        self.mapfile = mapfile
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   112
        self.commitcache = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   113
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   114
        self.map = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   115
        for l in file(self.mapfile):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   116
            sv, dv = l[:-1].split()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   117
            self.map[sv] = dv
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   118
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   119
    def walktree(self, heads):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   120
        visit = heads
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   121
        known = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   122
        parents = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   123
        while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   124
            n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   125
            if n in known or n in self.map: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   126
            known[n] = 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   127
            self.commitcache[n] = self.source.getcommit(n)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   128
            cp = self.commitcache[n][0]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   129
            for p in cp:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   130
                parents.setdefault(n, []).append(p)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   131
                visit.append(p)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   132
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   133
        return parents
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   134
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   135
    def toposort(self, parents):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   136
        visit = parents.keys()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   137
        seen = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   138
        children = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   139
        while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   140
            n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   141
            if n in seen: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   142
            seen[n] = 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   143
            pc = 0
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   144
            if n in parents:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   145
                for p in parents[n]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   146
                    if p not in self.map: pc += 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   147
                    visit.append(p)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   148
                    children.setdefault(p, []).append(n)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   149
            if not pc: root = n
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   150
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   151
        s = []
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   152
        removed = {}
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   153
        visit = parents.keys()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   154
        while visit:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   155
            n = visit.pop(0)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   156
            if n in removed: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   157
            dep = 0
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   158
            if n in parents:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   159
                for p in parents[n]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   160
                    if p in self.map: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   161
                    if p not in removed:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   162
                        # we're still dependent
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   163
                        visit.append(n)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   164
                        dep = 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   165
                        break
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   166
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   167
            if not dep:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   168
                # all n's parents are in the list
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   169
                removed[n] = 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   170
                s.append(n)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   171
                if n in children:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   172
                    for c in children[n]:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   173
                        visit.insert(0, c)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   174
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   175
        return s
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   176
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   177
    def copy(self, rev):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   178
        p, a, d, t = self.commitcache[rev]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   179
        files = self.source.getchanges(rev)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   180
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   181
        for f,v,e in files:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   182
            try:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   183
                data = self.source.getfile(f, v)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   184
            except IOError, inst:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   185
                self.dest.delfile(f)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   186
            else:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   187
                self.dest.putfile(f, e, data)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   188
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   189
        r = [self.map[v] for v in p]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   190
        f = [f for f,v,e in files]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   191
        self.map[rev] = self.dest.putcommit(f, r, a, d, t)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   192
        file(self.mapfile, "a").write("%s %s\n" % (rev, self.map[rev]))
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   193
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   194
    def convert(self):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   195
        heads = self.source.getheads()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   196
        parents = self.walktree(heads)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   197
        t = self.toposort(parents)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   198
        num = len(t)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   199
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   200
        for c in t:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   201
            num -= 1
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   202
            if c in self.map: continue
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   203
            desc = self.commitcache[c][3].splitlines()[0]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   204
            print num, desc
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   205
            self.copy(c)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   206
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   207
gitpath, hgpath, mapfile = sys.argv[1:]
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   208
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   209
c = convert(convert_git(gitpath), convert_mercurial(hgpath), mapfile)
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
   210
c.convert()