hgext/convert/monotone.py
author Patrick Mezard <pmezard@gmail.com>
Thu, 20 Mar 2008 23:32:43 +0100
changeset 6332 950e72fc7cf3
parent 6307 6840668e3bf6
child 6376 b40e90341ae2
permissions -rw-r--r--
convert: allow missing tools not to stop source type detection
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
     1
# monotone support for the convert extension
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
     2
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
     3
import os, re, time
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
     4
from mercurial import util
6332
950e72fc7cf3 convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents: 6307
diff changeset
     5
from common import NoRepo, MissingTool, commit, converter_source, checktool
950e72fc7cf3 convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents: 6307
diff changeset
     6
from common import commandline
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
     7
from mercurial.i18n import _
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
     8
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
     9
class monotone_source(converter_source, commandline):
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    10
    def __init__(self, ui, path=None, rev=None):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    11
        converter_source.__init__(self, ui, path, rev)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    12
        commandline.__init__(self, ui, 'mtn')
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    13
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    14
        self.ui = ui
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    15
        self.path = path
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    16
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    17
        # regular expressions for parsing monotone output
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    18
        space    = r'\s*'
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    19
        name     = r'\s+"((?:[^"]|\\")*)"\s*'
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    20
        value    = name
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    21
        revision = r'\s+\[(\w+)\]\s*'
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    22
        lines    = r'(?:.|\n)+'
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    23
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    24
        self.dir_re      = re.compile(space + "dir" + name)
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    25
        self.file_re     = re.compile(space + "file" + name + "content" + revision)
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    26
        self.add_file_re = re.compile(space + "add_file" + name + "content" + revision)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    27
        self.patch_re    = re.compile(space + "patch" + name + "from" + revision + "to" + revision)
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    28
        self.rename_re   = re.compile(space + "rename" + name + "to" + name)
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    29
        self.tag_re      = re.compile(space + "tag" + name + "revision" + revision)
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    30
        self.cert_re     = re.compile(lines + space + "name" + name + "value" + value)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    31
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    32
        attr = space + "file" + lines + space + "attr" + space
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    33
        self.attr_execute_re = re.compile(attr  + '"mtn:execute"' + space + '"true"')
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    34
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    35
        # cached data
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    36
        self.manifest_rev = None
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    37
        self.manifest = None
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    38
        self.files = None
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    39
        self.dirs  = None
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    40
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    41
        norepo = NoRepo (_("%s does not look like a monotone repo") % path)
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    42
        if not os.path.exists(path):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    43
            raise norepo
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    44
6332
950e72fc7cf3 convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents: 6307
diff changeset
    45
        checktool('mtn', abort=False)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    46
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    47
        # test if there are any revisions
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    48
        self.rev = None
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    49
        try:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    50
            self.getheads()
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    51
        except:
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    52
            raise norepo
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    53
        self.rev = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    54
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    55
    def mtnrun(self, *args, **kwargs):
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    56
        kwargs['d'] = self.path
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    57
        return self.run0('automate', *args, **kwargs)
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    58
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    59
    def mtnloadmanifest(self, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    60
        if self.manifest_rev == rev:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    61
            return
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    62
        self.manifest = self.mtnrun("get_manifest_of", rev).split("\n\n")
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    63
        self.manifest_rev = rev
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    64
        self.files = {}
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    65
        self.dirs = {}
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    66
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    67
        for e in self.manifest:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    68
            m = self.file_re.match(e)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    69
            if m:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    70
                attr = ""
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    71
                name = m.group(1)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    72
                node = m.group(2)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    73
                if self.attr_execute_re.match(e):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    74
                    attr += "x"
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    75
                self.files[name] = (node, attr)
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    76
            m = self.dir_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    77
            if m:
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    78
                self.dirs[m.group(1)] = True
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    79
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    80
    def mtnisfile(self, name, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    81
        # a non-file could be a directory or a deleted or renamed file
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    82
        self.mtnloadmanifest(rev)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    83
        try:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    84
            self.files[name]
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    85
            return True
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    86
        except KeyError:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    87
            return False
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    88
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    89
    def mtnisdir(self, name, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    90
        self.mtnloadmanifest(rev)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    91
        try:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    92
            self.dirs[name]
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    93
            return True
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    94
        except KeyError:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    95
            return False
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
    96
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    97
    def mtngetcerts(self, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    98
        certs = {"author":"<missing>", "date":"<missing>",
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
    99
            "changelog":"<missing>", "branch":"<missing>"}
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   100
        cert_list = self.mtnrun("certs", rev).split("\n\n")
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   101
        for e in cert_list:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   102
            m = self.cert_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   103
            if m:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   104
                certs[m.group(1)] = m.group(2)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   105
        return certs
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   106
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   107
    def mtnrenamefiles(self, files, fromdir, todir):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   108
        renamed = {}
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   109
        for tofile in files:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   110
            suffix = tofile.lstrip(todir)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   111
            if todir + suffix == tofile:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   112
                renamed[tofile] = (fromdir + suffix).lstrip("/")
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   113
        return renamed
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   114
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   115
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   116
    # implement the converter_source interface:
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   117
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   118
    def getheads(self):
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   119
        if not self.rev:
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   120
            return self.mtnrun("leaves").splitlines()
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   121
        else:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   122
            return [self.rev]
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   123
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   124
    def getchanges(self, rev):
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   125
        #revision = self.mtncmd("get_revision %s" % rev).split("\n\n")
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   126
        revision = self.mtnrun("get_revision", rev).split("\n\n")
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   127
        files = {}
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   128
        copies = {}
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   129
        for e in revision:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   130
            m = self.add_file_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   131
            if m:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   132
                files[m.group(1)] = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   133
            m = self.patch_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   134
            if m:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   135
                files[m.group(1)] = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   136
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   137
            # Delete/rename is handled later when the convert engine
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   138
            # discovers an IOError exception from getfile,
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   139
            # but only if we add the "from" file to the list of changes.
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   140
            m = self.rename_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   141
            if m:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   142
                toname = m.group(2)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   143
                fromname = m.group(1)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   144
                if self.mtnisfile(toname, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   145
                    copies[toname] = fromname
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   146
                    files[toname] = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   147
                    files[fromname] = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   148
                if self.mtnisdir(toname, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   149
                    renamed = self.mtnrenamefiles(self.files, fromname, toname)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   150
                    for tofile, fromfile in renamed.items():
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   151
                        self.ui.debug (_("copying file in renamed dir from '%s' to '%s'") % (fromfile, tofile), '\n')
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   152
                        files[tofile] = rev
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   153
                    for fromfile in renamed.values():
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   154
                        files[fromfile] = rev
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   155
        return (files.items(), copies)
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   156
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   157
    def getmode(self, name, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   158
        self.mtnloadmanifest(rev)
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   159
        try:
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   160
            node, attr = self.files[name]
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   161
            return attr
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   162
        except KeyError:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   163
            return ""
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   164
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   165
    def getfile(self, name, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   166
        if not self.mtnisfile(name, rev):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   167
            raise IOError() # file was deleted or renamed
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   168
        try:
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   169
            return self.mtnrun("get_file_of", name, r=rev)
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   170
        except:
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   171
            raise IOError() # file was deleted or renamed
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   172
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   173
    def getcommit(self, rev):
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   174
        certs   = self.mtngetcerts(rev)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   175
        return commit(
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   176
            author=certs["author"],
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   177
            date=util.datestr(util.strdate(certs["date"], "%Y-%m-%dT%H:%M:%S")),
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   178
            desc=certs["changelog"],
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   179
            rev=rev,
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   180
            parents=self.mtnrun("parents", rev).splitlines(),
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   181
            branch=certs["branch"])
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   182
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   183
    def gettags(self):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   184
        tags = {}
6307
6840668e3bf6 cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents: 6306
diff changeset
   185
        for e in self.mtnrun("tags").split("\n\n"):
6306
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   186
            m = self.tag_re.match(e)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   187
            if m:
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   188
                tags[m.group(1)] = m.group(2)
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   189
        return tags
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   190
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   191
    def getchangedfiles(self, rev, i):
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   192
        # This function is only needed to support --filemap
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   193
        # ... and we don't support that
2f9de4aaea9e initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff changeset
   194
        raise NotImplementedError()