hgext/convert/p4.py
author Eugene Baranov <eug.baranov@gmail.com>
Thu, 30 Jul 2015 00:58:05 +0100
branchstable
changeset 25882 97a9f7602014
parent 25805 584044e5ad57
child 25884 b810b59eca62
permissions -rw-r--r--
convert: when getting file from Perforce concatenate data at the end As it turned out, even when getting relatively small files, concatenating string data every time when new chunk is received is very inefficient. Maintaining a string list of data chunks and concatenating everything in one go at the end seems much more efficient - in my testing it made getting 40 MB file 7 times faster, whilst converting of a particularly big changelist with some big files went down from 20 hours to 3 hours.
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
25788
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    26
def decodefilename(filename):
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    27
    """Perforce escapes special characters @, #, *, or %
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    28
    with %40, %23, %2A, or %25 respectively
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    29
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    30
    >>> decodefilename('portable-net45%252Bnetcore45%252Bwp8%252BMonoAndroid')
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    31
    'portable-net45%2Bnetcore45%2Bwp8%2BMonoAndroid'
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    32
    >>> decodefilename('//Depot/Directory/%2525/%2523/%23%40.%2A')
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    33
    '//Depot/Directory/%25/%23/#@.*'
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    34
    """
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    35
    replacements = [('%2A', '*'), ('%23', '#'), ('%40', '@'), ('%25', '%')]
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    36
    for k, v in replacements:
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    37
        filename = filename.replace(k, v)
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    38
    return filename
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
    39
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    40
class p4_source(converter_source):
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
    41
    def __init__(self, ui, path, revs=None):
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
    42
        super(p4_source, self).__init__(ui, path, revs=revs)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    43
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
    44
        if "/" in path and not path.startswith('//'):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
    45
            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
    46
7905
d596b1f2935a convert: missing p4 tool is only slightly fatal
Mads Kiilerich <mads@kiilerich.com>
parents: 7869
diff changeset
    47
        checktool('p4', abort=False)
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    48
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    49
        self.p4changes = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    50
        self.heads = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    51
        self.changeset = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    52
        self.files = {}
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
    53
        self.copies = {}
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    54
        self.tags = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    55
        self.lastbranch = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    56
        self.parent = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    57
        self.encoding = "latin_1"
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    58
        self.depotname = {}           # mapping from local name to depot name
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
    59
        self.localname = {} # mapping from depot name to local name
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    60
        self.re_type = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    61
            "([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
    62
            "(\+\w+)?$")
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    63
        self.re_keywords = re.compile(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    64
            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
    65
            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
    66
        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
    67
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
    68
        if revs and len(revs) > 1:
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
    69
            raise util.Abort(_("p4 source does not support specifying "
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
    70
                               "multiple revisions"))
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    71
        self._parse(ui, path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    72
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    73
    def _parse_view(self, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    74
        "Read changes affecting the path"
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
    75
        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
    76
        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
    77
        for d in loaditer(stdout):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    78
            c = d.get("change", None)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    79
            if c:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    80
                self.p4changes[c] = True
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    81
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    82
    def _parse(self, ui, path):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    83
        "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
    84
        ui.status(_('reading p4 views\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    85
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    86
        # read client spec or view
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    87
        if "/" in path:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    88
            self._parse_view(path)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    89
            if path.startswith("//") and path.endswith("/..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    90
                views = {path[:-3]:""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    91
            else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    92
                views = {"//": ""}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    93
        else:
11347
18680b0e20a7 Fix shell quoting on p4 conversion
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 11134
diff changeset
    94
            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
    95
            clientspec = marshal.load(util.popen(cmd, mode='rb'))
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
    96
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    97
            views = {}
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    98
            for client in clientspec:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
    99
                if client.startswith("View"):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   100
                    sview, cview = clientspec[client].split()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   101
                    self._parse_view(sview)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   102
                    if sview.endswith("...") and cview.endswith("..."):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   103
                        sview = sview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   104
                        cview = cview[:-3]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   105
                    cview = cview[2:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   106
                    cview = cview[cview.find("/") + 1:]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   107
                    views[sview] = cview
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   108
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   109
        # 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
   110
        self.p4changes = self.p4changes.keys()
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   111
        self.p4changes.sort(key=int)
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   112
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   113
        # list with depot pathnames, longest first
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   114
        vieworder = views.keys()
9039
8761863c3118 p4: simplify sort key
Martin Geisler <mg@lazybytes.net>
parents: 8843
diff changeset
   115
        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
   116
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   117
        # handle revision limiting
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   118
        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
   119
        self.p4changes = [x for x in self.p4changes
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   120
                          if ((not startrev or int(x) >= int(startrev)) and
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
   121
                              (not self.revs or int(x) <= int(self.revs[0])))]
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   122
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   123
        # 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
   124
        ui.status(_('collecting p4 changelists\n'))
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   125
        lastid = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   126
        for change in self.p4changes:
12891
b69fd38a034e convert: Work around p4 instability (issue2465)
Mike Sperber <sperber@deinprogramm.de>
parents: 12401
diff changeset
   127
            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
   128
            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
   129
            d = marshal.load(stdout)
21758
c27a37678508 p4: accept changesets with no description (issue4282)
Matt Mackall <mpm@selenic.com>
parents: 16514
diff changeset
   130
            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
   131
            shortdesc = desc.split("\n", 1)[0]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   132
            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
   133
            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
   134
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   135
            if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   136
                parents = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   137
            else:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   138
                parents = []
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   139
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   140
            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
   141
            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
   142
                       date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
25805
584044e5ad57 convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25788
diff changeset
   143
                       parents=parents, desc=desc, branch=None,
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   144
                       extra={"p4": change})
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   145
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   146
            files = []
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   147
            copies = {}
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   148
            copiedfiles = []
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   149
            i = 0
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   150
            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
   151
                oldname = d["depotFile%d" % i]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   152
                filename = None
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   153
                for v in vieworder:
25776
809c3e4a9e31 convert: ignore case changes in vieworder for Perforce
Eugene Baranov <eug.baranov@gmail.com>
parents: 25775
diff changeset
   154
                    if oldname.lower().startswith(v.lower()):
25788
a36fd0993522 convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents: 25776
diff changeset
   155
                        filename = decodefilename(views[v] + oldname[len(v):])
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   156
                        break
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   157
                if filename:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   158
                    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
   159
                    self.depotname[filename] = oldname
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   160
                    if (d.get("action%d" % i) == "move/add"):
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   161
                        copiedfiles.append(filename)
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   162
                    self.localname[oldname] = filename
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   163
                i += 1
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   164
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   165
            # Collect information about copied files
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   166
            for filename in copiedfiles:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   167
                oldname = self.depotname[filename]
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   168
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   169
                flcmd = 'p4 -G filelog %s' \
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   170
                      % util.shellquote(oldname)
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   171
                flstdout = util.popen(flcmd, mode='rb')
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   172
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   173
                copiedfilename = None
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   174
                for d in loaditer(flstdout):
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   175
                    copiedoldname = None
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   176
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   177
                    i = 0
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   178
                    while ("change%d" % i) in d:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   179
                        if (d["change%d" % i] == change and
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   180
                            d["action%d" % i] == "move/add"):
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   181
                            j = 0
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   182
                            while ("file%d,%d" % (i, j)) in d:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   183
                                if d["how%d,%d" % (i, j)] == "moved from":
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   184
                                    copiedoldname = d["file%d,%d" % (i, j)]
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   185
                                    break
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   186
                                j += 1
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   187
                        i += 1
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   188
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   189
                    if copiedoldname and copiedoldname in self.localname:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   190
                        copiedfilename = self.localname[copiedoldname]
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   191
                        break
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   192
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   193
                if copiedfilename:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   194
                    copies[filename] = copiedfilename
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   195
                else:
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   196
                    ui.warn(_("cannot find source for copied file: %s@%s\n")
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   197
                            % (filename, change))
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   198
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   199
            self.changeset[change] = c
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   200
            self.files[change] = files
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   201
            self.copies[change] = copies
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   202
            lastid = change
7869
bc027d72c289 cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7823
diff changeset
   203
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   204
        if lastid:
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   205
            self.heads = [lastid]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   206
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   207
    def getheads(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   208
        return self.heads
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   209
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   210
    def getfile(self, name, rev):
11348
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
   211
        cmd = 'p4 -G print %s' \
ad0a334eef16 p4: fix long line and bad spacing around %
Martin Geisler <mg@aragost.com>
parents: 11347
diff changeset
   212
            % util.shellquote("%s#%s" % (self.depotname[name], rev))
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   213
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   214
        lasterror = None
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   215
        while True:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   216
            stdout = util.popen(cmd, mode='rb')
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   217
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   218
            mode = None
25882
97a9f7602014 convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents: 25805
diff changeset
   219
            contents = []
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   220
            keywords = None
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   221
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   222
            for d in loaditer(stdout):
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   223
                code = d["code"]
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   224
                data = d.get("data")
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
   225
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   226
                if code == "error":
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   227
                    # if this is the first time error happened
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   228
                    # re-attempt getting the file
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   229
                    if not lasterror:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   230
                        lasterror = IOError(d["generic"], data)
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   231
                        # this will exit inner-most for-loop
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   232
                        break
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   233
                    else:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   234
                        raise lasterror
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
   235
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   236
                elif code == "stat":
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   237
                    action = d.get("action")
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   238
                    if action in ["purge", "delete", "move/delete"]:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   239
                        return None, None
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   240
                    p4type = self.re_type.match(d["type"])
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   241
                    if p4type:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   242
                        mode = ""
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   243
                        flags = ((p4type.group(1) or "")
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   244
                               + (p4type.group(3) or ""))
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   245
                        if "x" in flags:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   246
                            mode = "x"
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   247
                        if p4type.group(2) == "symlink":
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   248
                            mode = "l"
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   249
                        if "ko" in flags:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   250
                            keywords = self.re_keywords_old
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   251
                        elif "k" in flags:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   252
                            keywords = self.re_keywords
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8829
diff changeset
   253
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   254
                elif code == "text" or code == "binary":
25882
97a9f7602014 convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents: 25805
diff changeset
   255
                    contents.append(data)
25775
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   256
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   257
                lasterror = None
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   258
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   259
            if not lasterror:
220d9ae6a9a8 convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents: 25760
diff changeset
   260
                break
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   261
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   262
        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
   263
            return None, None
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   264
25882
97a9f7602014 convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents: 25805
diff changeset
   265
        contents = ''.join(contents)
97a9f7602014 convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents: 25805
diff changeset
   266
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
   267
        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
   268
            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
   269
        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
   270
            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
   271
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
   272
        return contents, mode
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   273
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   274
    def getchanges(self, rev, full):
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   275
        if full:
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   276
            raise util.Abort(_("convert from p4 do not support --full"))
25751
17a9da909186 convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents: 25748
diff changeset
   277
        return self.files[rev], self.copies[rev], set()
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   278
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   279
    def getcommit(self, rev):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   280
        return self.changeset[rev]
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   281
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   282
    def gettags(self):
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   283
        return self.tags
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   284
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff changeset
   285
    def getchangedfiles(self, rev, i):
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8066
diff changeset
   286
        return sorted([x[0] for x in self.files[rev]])