hgext/convert/p4.py
author Mads Kiilerich <madski@unity3d.com>
Thu, 19 Mar 2015 17:40:19 +0100
changeset 24395 216fa1ba9993
parent 22300 35ab037de989
child 25745 501c51d60792
child 25748 baea47cafe75
permissions -rw-r--r--
convert: optimize convert of files that are unmodified from p2 in merges Conversion of a merge starts with p1 and re-adds the files that were changed in the merge or came unmodified from p2. Files that are unmodified from p1 will thus not be touched and take no time. Files that are unmodified from p2 would be retrieved and rehashed. They would end up getting the same hash as in p2 and end up reusing the filelog entry and look like the p1 case ... but it was slow. Instead, make getchanges also return 'files that are unmodified from p2' so the sink can reuse the existing p2 entry instead of calling getfile. Reuse of filelog entries can make a big difference when files are big and with long revlong chains so they take time to retrieve and hash, or when using an expensive custom getfile function (think http://mercurial.selenic.com/wiki/ConvertExtension#Customization with a code reformatter). This in combination with changes to reuse filectx entries in localrepo._filecommit make 'unchanged from p2' almost as fast as 'unchanged from p1'. This is so far only implemented for the combination of hg source and hg sink. This is a refactoring/optimization. It is covered by existing tests and show no changes - which is a good thing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     1
# Perforce source for convert extension.
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     2
#
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     3
# Copyright 2009, Frank Kingswood <frank@kingswood-consulting.co.uk>
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9476
diff changeset
     6
# GNU General Public License version 2 or any later version.
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     7
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     8
from mercurial import util
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
     9
from mercurial.i18n import _
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    10
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7905
diff changeset
    11
from common import commit, converter_source, checktool, NoRepo
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    12
import marshal
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
    13
import re
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    14
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    15
def loaditer(f):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    16
    "Yield the dictionary objects generated by p4"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    17
    try:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    18
        while True:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    19
            d = marshal.load(f)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    20
            if not d:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    21
                break
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    22
            yield d
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    23
    except EOFError:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    24
        pass
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    25
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    26
class p4_source(converter_source):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    27
    def __init__(self, ui, path, rev=None):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    28
        super(p4_source, self).__init__(ui, path, rev=rev)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    29
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
    30
        if "/" in path and not path.startswith('//'):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
    31
            raise NoRepo(_('%s does not look like a P4 repository') % path)
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7905
diff changeset
    32
7905
d596b1f2935a convert: missing p4 tool is only slightly fatal
Mads Kiilerich <mads@kiilerich.com>
parents: 7869
diff changeset
    33
        checktool('p4', abort=False)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    34
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    35
        self.p4changes = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    36
        self.heads = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    37
        self.changeset = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    38
        self.files = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    39
        self.tags = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    40
        self.lastbranch = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    41
        self.parent = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    42
        self.encoding = "latin_1"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    43
        self.depotname = {}           # mapping from local name to depot name
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    44
        self.re_type = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    45
            "([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)"
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    46
            "(\+\w+)?$")
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    47
        self.re_keywords = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    48
            r"\$(Id|Header|Date|DateTime|Change|File|Revision|Author)"
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    49
            r":[^$\n]*\$")
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
    50
        self.re_keywords_old = re.compile("\$(Id|Header):[^$\n]*\$")
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    51
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    52
        self._parse(ui, path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    53
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    54
    def _parse_view(self, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    55
        "Read changes affecting the path"
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
    56
        cmd = 'p4 -G changes -s submitted %s' % util.shellquote(path)
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
    57
        stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    58
        for d in loaditer(stdout):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    59
            c = d.get("change", None)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    60
            if c:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    61
                self.p4changes[c] = True
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    62
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    63
    def _parse(self, ui, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    64
        "Prepare list of P4 filenames and revisions to import"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    65
        ui.status(_('reading p4 views\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    66
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    67
        # read client spec or view
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    68
        if "/" in path:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    69
            self._parse_view(path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    70
            if path.startswith("//") and path.endswith("/..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    71
                views = {path[:-3]:""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    72
            else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    73
                views = {"//": ""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    74
        else:
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
    75
            cmd = 'p4 -G client -o %s' % util.shellquote(path)
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
    76
            clientspec = marshal.load(util.popen(cmd, mode='rb'))
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
    77
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    78
            views = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    79
            for client in clientspec:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    80
                if client.startswith("View"):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    81
                    sview, cview = clientspec[client].split()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    82
                    self._parse_view(sview)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    83
                    if sview.endswith("...") and cview.endswith("..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    84
                        sview = sview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    85
                        cview = cview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    86
                    cview = cview[2:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    87
                    cview = cview[cview.find("/") + 1:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    88
                    views[sview] = cview
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    89
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    90
        # list of changes that affect our source files
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    91
        self.p4changes = self.p4changes.keys()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    92
        self.p4changes.sort(key=int)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    93
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    94
        # list with depot pathnames, longest first
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    95
        vieworder = views.keys()
9039
8761863c3118 p4: simplify sort key
Martin Geisler <mg@lazybytes.net>
parents: 8843
diff changeset
    96
        vieworder.sort(key=len, reverse=True)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    97
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    98
        # handle revision limiting
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    99
        startrev = self.ui.config('convert', 'p4.startrev', default=0)
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   100
        self.p4changes = [x for x in self.p4changes
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   101
                          if ((not startrev or int(x) >= int(startrev)) and
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   102
                              (not self.rev or int(x) <= int(self.rev)))]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   103
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   104
        # now read the full changelists to get the list of file revisions
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   105
        ui.status(_('collecting p4 changelists\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   106
        lastid = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   107
        for change in self.p4changes:
12891
b69fd38a034e convert: Work around p4 instability (issue2465)
Mike Sperber <sperber@deinprogramm.de>
parents: 12401
diff changeset
   108
            cmd = "p4 -G describe -s %s" % change
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
   109
            stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   110
            d = marshal.load(stdout)
21758
c27a37678508 p4: accept changesets with no description (issue4282)
Matt Mackall <mpm@selenic.com>
parents: 16514
diff changeset
   111
            desc = self.recode(d.get("desc", ""))
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   112
            shortdesc = desc.split("\n", 1)[0]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   113
            t = '%s %s' % (d["change"], repr(shortdesc)[1:-1])
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   114
            ui.status(util.ellipsis(t, 80) + '\n')
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   115
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   116
            if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   117
                parents = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   118
            else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   119
                parents = []
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   120
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   121
            date = (int(d["time"]), 0)     # timezone not set
16514
363e808de349 i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 12891
diff changeset
   122
            c = commit(author=self.recode(d["user"]),
363e808de349 i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 12891
diff changeset
   123
                       date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   124
                       parents=parents, desc=desc, branch='',
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   125
                       extra={"p4": change})
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   126
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   127
            files = []
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   128
            i = 0
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   129
            while ("depotFile%d" % i) in d and ("rev%d" % i) in d:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   130
                oldname = d["depotFile%d" % i]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   131
                filename = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   132
                for v in vieworder:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   133
                    if oldname.startswith(v):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   134
                        filename = views[v] + oldname[len(v):]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   135
                        break
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   136
                if filename:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   137
                    files.append((filename, d["rev%d" % i]))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   138
                    self.depotname[filename] = oldname
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   139
                i += 1
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   140
            self.changeset[change] = c
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   141
            self.files[change] = files
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   142
            lastid = change
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   143
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   144
        if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   145
            self.heads = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   146
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   147
    def getheads(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   148
        return self.heads
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   149
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   150
    def getfile(self, name, rev):
11348
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
   151
        cmd = 'p4 -G print %s' \
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
   152
            % util.shellquote("%s#%s" % (self.depotname[name], rev))
9474
6ea653272c09 convert: fix marshalling in P4 convert extension to use a binary stream
Peter Ingebretson <pingebre@yahoo.com>
parents: 8843
diff changeset
   153
        stdout = util.popen(cmd, mode='rb')
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   154
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   155
        mode = None
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   156
        contents = ""
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   157
        keywords = None
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   158
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   159
        for d in loaditer(stdout):
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   160
            code = d["code"]
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   161
            data = d.get("data")
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   162
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   163
            if code == "error":
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   164
                raise IOError(d["generic"], data)
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
   165
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   166
            elif code == "stat":
22294
754f208ce21d convert: p4: ignore purged files with p4d 2012.2 and later
Mads Kiilerich <madski@unity3d.com>
parents: 21758
diff changeset
   167
                if d.get("action") == "purge":
754f208ce21d convert: p4: ignore purged files with p4d 2012.2 and later
Mads Kiilerich <madski@unity3d.com>
parents: 21758
diff changeset
   168
                    return None, None
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   169
                p4type = self.re_type.match(d["type"])
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   170
                if p4type:
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   171
                    mode = ""
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   172
                    flags = (p4type.group(1) or "") + (p4type.group(3) or "")
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   173
                    if "x" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   174
                        mode = "x"
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   175
                    if p4type.group(2) == "symlink":
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   176
                        mode = "l"
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   177
                    if "ko" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   178
                        keywords = self.re_keywords_old
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   179
                    elif "k" in flags:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   180
                        keywords = self.re_keywords
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
   181
12401
4cdaf1adafc8 backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents: 12387
diff changeset
   182
            elif code == "text" or code == "binary":
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   183
                contents += data
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   184
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   185
        if mode is None:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22294
diff changeset
   186
            return None, None
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   187
8829
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   188
        if keywords:
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   189
            contents = keywords.sub("$\\1$", contents)
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   190
        if mode == "l" and contents.endswith("\n"):
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   191
            contents = contents[:-1]
ce4b92f5cea7 convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 8225
diff changeset
   192
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
   193
        return contents, mode
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   194
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   195
    def getchanges(self, rev, full):
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   196
        if full:
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   197
            raise util.Abort(_("convert from p4 do not support --full"))
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
   198
        return self.files[rev], {}, set()
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   199
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   200
    def getcommit(self, rev):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   201
        return self.changeset[rev]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   202
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   203
    def gettags(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   204
        return self.tags
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   205
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   206
    def getchangedfiles(self, rev, i):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8066
diff changeset
   207
        return sorted([x[0] for x in self.files[rev]])