hgext/convert/hg.py
author Bryan O'Sullivan <bos@serpentine.com>
Thu, 26 Jul 2007 13:34:36 -0700
changeset 5017 06329efa722d
parent 5016 4ebc8693ce72
child 5038 8f157190075e
permissions -rw-r--r--
convert: get rid of "hg." prefix where not needed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
     1
# hg backend for convert extension
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
     2
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     3
# Note for hg->hg conversion: Old versions of Mercurial didn't trim
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     4
# the whitespace from the ends of commit messages, but new versions
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     5
# do.  Changesets created by those older versions, then converted, may
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     6
# thus have different hashes for changesets that are otherwise
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     7
# identical.
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     8
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
     9
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
    10
import os, time
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    11
from mercurial.i18n import _
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
    12
from mercurial.node import *
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    13
from mercurial import hg, lock, revlog, util
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
    14
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
    15
from common import NoRepo, commit, converter_source, converter_sink
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    16
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
    17
class mercurial_sink(converter_sink):
4763
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
    18
    def __init__(self, ui, path):
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    19
        self.path = path
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
    20
        self.ui = ui
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
    21
        try:
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
    22
            self.repo = hg.repository(self.ui, path)
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
    23
        except:
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
    24
            raise NoRepo("could not open hg repo %s as sink" % path)
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    25
        self.lock = None
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    26
        self.wlock = None
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    27
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    28
    def before(self):
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    29
        self.lock = self.repo.lock()
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    30
        self.wlock = self.repo.wlock()
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    31
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    32
    def after(self):
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    33
        self.lock = None
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    34
        self.wlock = None
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
    35
5011
89fbb0a5e8e3 convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
    36
    def revmapfile(self):
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
    37
        return os.path.join(self.path, ".hg", "shamap")
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    38
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
    39
    def authorfile(self):
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
    40
        return os.path.join(self.path, ".hg", "authormap")
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
    41
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    42
    def getheads(self):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    43
        h = self.repo.changelog.heads()
5017
06329efa722d convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents: 5016
diff changeset
    44
        return [ hex(x) for x in h ]
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    45
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    46
    def putfile(self, f, e, data):
4082
6b2909e84203 convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents: 4062
diff changeset
    47
        self.repo.wwrite(f, data, e)
4906
30847b8af7ca dirstate: add __contains__ and make __getitem__ more useful
Matt Mackall <mpm@selenic.com>
parents: 4904
diff changeset
    48
        if f not in self.repo.dirstate:
4904
6fd953d5faea dirstate: break update into separate functions
Matt Mackall <mpm@selenic.com>
parents: 4873
diff changeset
    49
            self.repo.dirstate.add(f)
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    50
4765
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents: 4763
diff changeset
    51
    def copyfile(self, source, dest):
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents: 4763
diff changeset
    52
        self.repo.copy(source, dest)
b6a1f2c46c6c convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents: 4763
diff changeset
    53
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    54
    def delfile(self, f):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    55
        try:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    56
            os.unlink(self.repo.wjoin(f))
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    57
            #self.repo.remove([f])
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    58
        except:
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    59
            pass
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    60
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
    61
    def putcommit(self, files, parents, commit):
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
    62
        if not files:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
    63
            return hex(self.repo.changelog.tip())
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
    64
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
    65
        seen = {hex(nullid): 1}
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    66
        pl = []
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    67
        for p in parents:
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    68
            if p not in seen:
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    69
                pl.append(p)
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    70
                seen[p] = 1
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    71
        parents = pl
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    72
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    73
        if len(parents) < 2: parents.append("0" * 40)
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    74
        if len(parents) < 2: parents.append("0" * 40)
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    75
        p2 = parents.pop(0)
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
    76
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
    77
        text = commit.desc
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
    78
        extra = {}
4873
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
    79
        if commit.branch:
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
    80
            extra['branch'] = commit.branch
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
    81
        if commit.rev:
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
    82
            extra['convert_revision'] = commit.rev
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4873
diff changeset
    83
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    84
        while parents:
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    85
            p1 = p2
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    86
            p2 = parents.pop(0)
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
    87
            a = self.repo.rawcommit(files, text, commit.author, commit.date,
5017
06329efa722d convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents: 5016
diff changeset
    88
                                    bin(p1), bin(p2), extra=extra)
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
    89
            self.repo.dirstate.invalidate()
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    90
            text = "(octopus merge fixup)\n"
1389
9b3ef6f3cef5 convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents: 1388
diff changeset
    91
            p2 = hg.hex(self.repo.changelog.tip())
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
    92
1389
9b3ef6f3cef5 convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents: 1388
diff changeset
    93
        return p2
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
    94
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    95
    def puttags(self, tags):
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    96
        try:
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    97
            old = self.repo.wfile(".hgtags").read()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    98
            oldlines = old.splitlines(1)
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
    99
            oldlines.sort()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   100
        except:
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   101
            oldlines = []
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   102
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   103
        k = tags.keys()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   104
        k.sort()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   105
        newlines = []
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   106
        for tag in k:
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   107
            newlines.append("%s %s\n" % (tags[tag], tag))
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   108
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   109
        newlines.sort()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   110
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   111
        if newlines != oldlines:
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
   112
            self.ui.status("updating tags\n")
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   113
            f = self.repo.wfile(".hgtags", "w")
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   114
            f.write("".join(newlines))
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   115
            f.close()
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   116
            if not oldlines: self.repo.add([".hgtags"])
1335
bea6356b8bca git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents: 1237
diff changeset
   117
            date = "%s 0" % int(time.mktime(time.gmtime()))
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
   118
            self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
5017
06329efa722d convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents: 5016
diff changeset
   119
                                date, self.repo.changelog.tip(), nullid)
06329efa722d convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents: 5016
diff changeset
   120
            return hex(self.repo.changelog.tip())
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   121
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   122
class mercurial_source(converter_source):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   123
    def __init__(self, ui, path, rev=None):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   124
        converter_source.__init__(self, ui, path, rev)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   125
        self.repo = hg.repository(self.ui, path)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   126
        self.lastrev = None
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   127
        self.lastctx = None
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   128
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   129
    def changectx(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   130
        if self.lastrev != rev:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   131
            self.lastctx = self.repo.changectx(rev)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   132
            self.lastrev = rev
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   133
        return self.lastctx
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   134
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   135
    def getheads(self):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   136
        return [hex(node) for node in self.repo.heads()]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   137
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   138
    def getfile(self, name, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   139
        try:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   140
            return self.changectx(rev).filectx(name).data()
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   141
        except revlog.LookupError, err:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   142
            raise IOError(err)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   143
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   144
    def getmode(self, name, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   145
        m = self.changectx(rev).manifest()
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   146
        return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '')
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   147
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   148
    def getchanges(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   149
        ctx = self.changectx(rev)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   150
        m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   151
        changes = [(name, rev) for name in m + a + r]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   152
        changes.sort()
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   153
        return changes
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   154
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   155
    def getcopies(self, ctx):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   156
        added = self.repo.status(ctx.parents()[0].node(), ctx.node())[1]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   157
        copies = {}
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   158
        for name in added:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   159
            try:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   160
                copies[name] = ctx.filectx(name).renamed()[0]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   161
            except TypeError:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   162
                pass
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   163
        return copies
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   164
        
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   165
    def getcommit(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   166
        ctx = self.changectx(rev)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   167
        parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid]
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   168
        return commit(author=ctx.user(), date=util.datestr(ctx.date()),
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   169
                      desc=ctx.description(), parents=parents,
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   170
                      branch=ctx.branch(), copies=self.getcopies(ctx))
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   171
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   172
    def gettags(self):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   173
        tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
   174
        return dict([(name, hex(node)) for name, node in tags])