hgext/convert/gnuarch.py
author Matt Harbison <matt_harbison@yahoo.com>
Wed, 22 Nov 2017 20:49:01 -0500
changeset 35176 671aba341d90
parent 29205 a0939666b836
child 35633 a981ab2a1b4c
permissions -rw-r--r--
convert: save an indicator of the repo type for sources and sinks This seems like basic info to have, and will be used shortly when deciding whether or not to wrap the class for lfs conversions. The other option is to just add a function to each class. But this seems better in that the strings aren't duplicated, and the constructor for most of these will run even if the VCS isn't installed, so it's easier to catch errors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8250
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     1
# gnuarch.py - GNU Arch support for the convert extension
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     2
#
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     3
#  Copyright 2008, 2009 Aleix Conchillo Flaque <aleix@member.fsf.org>
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     4
#  and others
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     5
#
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
     6
# 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: 9467
diff changeset
     7
# GNU General Public License version 2 or any later version.
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
     8
from __future__ import absolute_import
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
     9
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    10
import email
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    11
import os
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    12
import shutil
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    13
import stat
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    14
import tempfile
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28366
diff changeset
    15
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28366
diff changeset
    16
from mercurial.i18n import _
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    17
from mercurial import (
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    18
    encoding,
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    19
    error,
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    20
    util,
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    21
)
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    22
from . import common
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    23
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    24
class gnuarch_source(common.converter_source, common.commandline):
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    25
8778
c5f36402daad use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8668
diff changeset
    26
    class gnuarch_rev(object):
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    27
        def __init__(self, rev):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    28
            self.rev = rev
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    29
            self.summary = ''
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    30
            self.date = None
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    31
            self.author = ''
7583
77fec2d270ae convert/gnuarch: parse continuation-of revisions in gnuarch source
Edouard Gomez <ed.gomez@free.fr>
parents: 7582
diff changeset
    32
            self.continuationof = None
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    33
            self.add_files = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    34
            self.mod_files = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    35
            self.del_files = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    36
            self.ren_files = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    37
            self.ren_dirs = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    38
35176
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 29205
diff changeset
    39
    def __init__(self, ui, repotype, path, revs=None):
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 29205
diff changeset
    40
        super(gnuarch_source, self).__init__(ui, repotype, path, revs=revs)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    41
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    42
        if not os.path.exists(os.path.join(path, '{arch}')):
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    43
            raise common.NoRepo(_("%s does not look like a GNU Arch repository")
10938
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10394
diff changeset
    44
                         % path)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    45
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    46
        # Could use checktool, but we want to check for baz or tla.
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    47
        self.execmd = None
14271
4030630fb59c rename util.find_exe to findexe
Adrian Buehlmann <adrian@cadifra.com>
parents: 12344
diff changeset
    48
        if util.findexe('baz'):
6083
81a8667331e8 convert: detect baz before tla
Patrick Mezard <pmezard@gmail.com>
parents: 6079
diff changeset
    49
            self.execmd = 'baz'
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    50
        else:
14271
4030630fb59c rename util.find_exe to findexe
Adrian Buehlmann <adrian@cadifra.com>
parents: 12344
diff changeset
    51
            if util.findexe('tla'):
6083
81a8667331e8 convert: detect baz before tla
Patrick Mezard <pmezard@gmail.com>
parents: 6079
diff changeset
    52
                self.execmd = 'tla'
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    53
            else:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
    54
                raise error.Abort(_('cannot find a GNU Arch tool'))
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    55
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    56
        common.commandline.__init__(self, ui, self.execmd)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    57
15381
c519cd8f0169 backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents: 15355
diff changeset
    58
        self.path = os.path.realpath(path)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    59
        self.tmppath = None
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    60
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    61
        self.treeversion = None
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    62
        self.lastrev = None
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    63
        self.changes = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    64
        self.parents = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    65
        self.tags = {}
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
    66
        self.catlogparser = email.Parser.Parser()
11987
3145951e50fe convert: use encoding.encoding instead of locale.getpreferredencoding()
Brodie Rao <brodie@bitheap.org>
parents: 11986
diff changeset
    67
        self.encoding = encoding.encoding
7584
28563e94c471 convert/gnuarch: retrieve known archive names list
Edouard Gomez <ed.gomez@free.fr>
parents: 7583
diff changeset
    68
        self.archives = []
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    69
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    70
    def before(self):
7584
28563e94c471 convert/gnuarch: retrieve known archive names list
Edouard Gomez <ed.gomez@free.fr>
parents: 7583
diff changeset
    71
        # Get registered archives
28563e94c471 convert/gnuarch: retrieve known archive names list
Edouard Gomez <ed.gomez@free.fr>
parents: 7583
diff changeset
    72
        self.archives = [i.rstrip('\n')
28563e94c471 convert/gnuarch: retrieve known archive names list
Edouard Gomez <ed.gomez@free.fr>
parents: 7583
diff changeset
    73
                         for i in self.runlines0('archives', '-n')]
28563e94c471 convert/gnuarch: retrieve known archive names list
Edouard Gomez <ed.gomez@free.fr>
parents: 7583
diff changeset
    74
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    75
        if self.execmd == 'tla':
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    76
            output = self.run0('tree-version', self.path)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    77
        else:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    78
            output = self.run0('tree-version', '-d', self.path)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    79
        self.treeversion = output.strip()
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    80
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    81
        # Get name of temporary directory
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    82
        version = self.treeversion.split('/')
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    83
        self.tmppath = os.path.join(tempfile.gettempdir(),
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    84
                                    'hg-%s' % version[1])
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    85
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
    86
        # Generate parents dictionary
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    87
        self.parents[None] = []
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    88
        treeversion = self.treeversion
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    89
        child = None
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    90
        while treeversion:
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    91
            self.ui.status(_('analyzing tree version %s...\n') % treeversion)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    92
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    93
            archive = treeversion.split('/')[0]
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    94
            if archive not in self.archives:
8662
eaee3491ce11 convert/gnuarch: wrap long line, format kwargs without spaces
Martin Geisler <mg@lazybytes.net>
parents: 8250
diff changeset
    95
                self.ui.status(_('tree analysis stopped because it points to '
eaee3491ce11 convert/gnuarch: wrap long line, format kwargs without spaces
Martin Geisler <mg@lazybytes.net>
parents: 8250
diff changeset
    96
                                 'an unregistered archive %s...\n') % archive)
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    97
                break
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    98
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
    99
            # Get the complete list of revisions for that tree version
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   100
            output, status = self.runlines('revisions', '-r', '-f', treeversion)
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17391
diff changeset
   101
            self.checkexit(status, 'failed retrieving revisions for %s'
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   102
                           % treeversion)
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   103
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   104
            # No new iteration unless a revision has a continuation-of header
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   105
            treeversion = None
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   106
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   107
            for l in output:
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   108
                rev = l.strip()
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   109
                self.changes[rev] = self.gnuarch_rev(rev)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   110
                self.parents[rev] = []
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   111
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   112
                # Read author, date and summary
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   113
                catlog, status = self.run('cat-log', '-d', self.path, rev)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   114
                if status:
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   115
                    catlog  = self.run0('cat-archive-log', rev)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   116
                self._parsecatlog(catlog, rev)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   117
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   118
                # Populate the parents map
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   119
                self.parents[child].append(rev)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   120
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   121
                # Keep track of the current revision as the child of the next
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   122
                # revision scanned
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   123
                child = rev
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   124
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   125
                # Check if we have to follow the usual incremental history
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   126
                # or if we have to 'jump' to a different treeversion given
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   127
                # by the continuation-of header.
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   128
                if self.changes[rev].continuationof:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   129
                    treeversion = '--'.join(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   130
                        self.changes[rev].continuationof.split('--')[:-1])
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   131
                    break
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   132
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   133
                # If we reached a base-0 revision w/o any continuation-of
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   134
                # header, it means the tree history ends here.
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   135
                if rev[-6:] == 'base-0':
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   136
                    break
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   137
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   138
    def after(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9391
diff changeset
   139
        self.ui.debug('cleaning up %s\n' % self.tmppath)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   140
        shutil.rmtree(self.tmppath, ignore_errors=True)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   141
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   142
    def getheads(self):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   143
        return self.parents[None]
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   144
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   145
    def getfile(self, name, rev):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   146
        if rev != self.lastrev:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
   147
            raise error.Abort(_('internal calling inconsistency'))
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   148
12344
b6173aee4a47 Use lexists() instead of exists() where appropriate
Patrick Mezard <pmezard@gmail.com>
parents: 11987
diff changeset
   149
        if not os.path.lexists(os.path.join(self.tmppath, name)):
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 17424
diff changeset
   150
            return None, None
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   151
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10938
diff changeset
   152
        return self._getfile(name, rev)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   153
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   154
    def getchanges(self, rev, full):
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   155
        if full:
26779
aaa33ec3c951 grammar: use does instead of do where appropriate
timeless@mozdev.org
parents: 26587
diff changeset
   156
            raise error.Abort(_("convert from arch does not support --full"))
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   157
        self._update(rev)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   158
        changes = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   159
        copies = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   160
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   161
        for f in self.changes[rev].add_files:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   162
            changes.append((f, rev))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   163
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   164
        for f in self.changes[rev].mod_files:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   165
            changes.append((f, rev))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   166
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   167
        for f in self.changes[rev].del_files:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   168
            changes.append((f, rev))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   169
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   170
        for src in self.changes[rev].ren_files:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   171
            to = self.changes[rev].ren_files[src]
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   172
            changes.append((src, rev))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   173
            changes.append((to, rev))
7567
0946294d1f32 convert/gnuarch: fix switched copy source and destination
Patrick Mezard <pmezard@gmail.com>
parents: 6913
diff changeset
   174
            copies[to] = src
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   175
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   176
        for src in self.changes[rev].ren_dirs:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   177
            to = self.changes[rev].ren_dirs[src]
10394
4612cded5176 fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   178
            chgs, cps = self._rendirchanges(src, to)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   179
            changes += [(f, rev) for f in chgs]
7567
0946294d1f32 convert/gnuarch: fix switched copy source and destination
Patrick Mezard <pmezard@gmail.com>
parents: 6913
diff changeset
   180
            copies.update(cps)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   181
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   182
        self.lastrev = rev
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 24306
diff changeset
   183
        return sorted(set(changes)), copies, set()
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   184
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   185
    def getcommit(self, rev):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   186
        changes = self.changes[rev]
28366
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
   187
        return common.commit(author=changes.author, date=changes.date,
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
   188
                             desc=changes.summary, parents=self.parents[rev],
4e08b91a483f convert: gnuarch use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
   189
                             rev=rev)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   190
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   191
    def gettags(self):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   192
        return self.tags
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   193
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   194
    def _execute(self, cmd, *args, **kwargs):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   195
        cmdline = [self.execmd, cmd]
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   196
        cmdline += args
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   197
        cmdline = [util.shellquote(arg) for arg in cmdline]
17391
fc24c10424d2 util: replace util.nulldev with os.devnull
Ross Lagerwall <rosslagerwall@gmail.com>
parents: 15381
diff changeset
   198
        cmdline += ['>', os.devnull, '2>', os.devnull]
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   199
        cmdline = util.quotecommand(' '.join(cmdline))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   200
        self.ui.debug(cmdline, '\n')
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   201
        return os.system(cmdline)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   202
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   203
    def _update(self, rev):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9391
diff changeset
   204
        self.ui.debug('applying revision %s...\n' % rev)
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   205
        changeset, status = self.runlines('replay', '-d', self.tmppath,
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   206
                                              rev)
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   207
        if status:
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   208
            # Something went wrong while merging (baz or tla
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   209
            # issue?), get latest revision and try from there
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   210
            shutil.rmtree(self.tmppath, ignore_errors=True)
6049
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   211
            self._obtainrevision(rev)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   212
        else:
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   213
            old_rev = self.parents[rev][0]
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9391
diff changeset
   214
            self.ui.debug('computing changeset between %s and %s...\n'
7585
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   215
                          % (old_rev, rev))
075b7ef0f84d convert/gnuarch: follow continuation-of revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7584
diff changeset
   216
            self._parsechangeset(changeset, rev)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   217
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   218
    def _getfile(self, name, rev):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   219
        mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   220
        if stat.S_ISLNK(mode):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   221
            data = os.readlink(os.path.join(self.tmppath, name))
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22300
diff changeset
   222
            if mode:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22300
diff changeset
   223
                mode = 'l'
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22300
diff changeset
   224
            else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 22300
diff changeset
   225
                mode = ''
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   226
        else:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   227
            data = open(os.path.join(self.tmppath, name), 'rb').read()
25658
e93036747902 global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24395
diff changeset
   228
            mode = (mode & 0o111) and 'x' or ''
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   229
        return data, mode
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   230
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   231
    def _exclude(self, name):
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   232
        exclude = ['{arch}', '.arch-ids', '.arch-inventory']
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   233
        for exc in exclude:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   234
            if name.find(exc) != -1:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   235
                return True
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   236
        return False
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   237
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   238
    def _readcontents(self, path):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   239
        files = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   240
        contents = os.listdir(path)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   241
        while len(contents) > 0:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   242
            c = contents.pop()
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   243
            p = os.path.join(path, c)
6044
9360a58a09e6 convert: do not skip some lines in gnu arch summaries
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6037
diff changeset
   244
            # os.walk could be used, but here we avoid internal GNU
9360a58a09e6 convert: do not skip some lines in gnu arch summaries
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6037
diff changeset
   245
            # Arch files and directories, thus saving a lot time.
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   246
            if not self._exclude(p):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   247
                if os.path.isdir(p):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   248
                    contents += [os.path.join(c, f) for f in os.listdir(p)]
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   249
                else:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   250
                    files.append(c)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   251
        return files
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   252
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   253
    def _rendirchanges(self, src, dest):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   254
        changes = []
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   255
        copies = {}
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   256
        files = self._readcontents(os.path.join(self.tmppath, dest))
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   257
        for f in files:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   258
            s = os.path.join(src, f)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   259
            d = os.path.join(dest, f)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   260
            changes.append(s)
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   261
            changes.append(d)
7567
0946294d1f32 convert/gnuarch: fix switched copy source and destination
Patrick Mezard <pmezard@gmail.com>
parents: 6913
diff changeset
   262
            copies[d] = s
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   263
        return changes, copies
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   264
6049
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   265
    def _obtainrevision(self, rev):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9391
diff changeset
   266
        self.ui.debug('obtaining revision %s...\n' % rev)
7582
3b2383c90034 convert/gnuarch: use fully qualified revisions
Edouard Gomez <ed.gomez@free.fr>
parents: 7581
diff changeset
   267
        output = self._execute('get', rev, self.tmppath)
6049
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   268
        self.checkexit(output)
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9391
diff changeset
   269
        self.ui.debug('analyzing revision %s...\n' % rev)
6049
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   270
        files = self._readcontents(self.tmppath)
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   271
        self.changes[rev].add_files += files
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   272
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   273
    def _stripbasepath(self, path):
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   274
        if path.startswith('./'):
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   275
            return path[2:]
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   276
        return path
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   277
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   278
    def _parsecatlog(self, data, rev):
7578
7971650bdc73 convert/gnuarch: fix cat-log parsing
Edouard Gomez <ed.gomez@free.fr>
parents: 7577
diff changeset
   279
        try:
7971650bdc73 convert/gnuarch: fix cat-log parsing
Edouard Gomez <ed.gomez@free.fr>
parents: 7577
diff changeset
   280
            catlog = self.catlogparser.parsestr(data)
7592
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   281
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   282
            # Commit date
7578
7971650bdc73 convert/gnuarch: fix cat-log parsing
Edouard Gomez <ed.gomez@free.fr>
parents: 7577
diff changeset
   283
            self.changes[rev].date = util.datestr(
7971650bdc73 convert/gnuarch: fix cat-log parsing
Edouard Gomez <ed.gomez@free.fr>
parents: 7577
diff changeset
   284
                util.strdate(catlog['Standard-date'],
7971650bdc73 convert/gnuarch: fix cat-log parsing
Edouard Gomez <ed.gomez@free.fr>
parents: 7577
diff changeset
   285
                             '%Y-%m-%d %H:%M:%S'))
7592
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   286
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   287
            # Commit author
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   288
            self.changes[rev].author = self.recode(catlog['Creator'])
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   289
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   290
            # Commit description
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   291
            self.changes[rev].summary = '\n\n'.join((catlog['Summary'],
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   292
                                                    catlog.get_payload()))
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   293
            self.changes[rev].summary = self.recode(self.changes[rev].summary)
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   294
75ad51257c82 convert/gnuarch: recode cat-log parts to utf-8 to be hg.description friendly
Edouard Gomez <ed.gomez@free.fr>
parents: 7591
diff changeset
   295
            # Commit revision origin when dealing with a branch or tag
9391
2705e6816d33 use 'x in dict' instead of 'dict.has_key(x)'
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8778
diff changeset
   296
            if 'Continuation-of' in catlog:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   297
                self.changes[rev].continuationof = self.recode(
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   298
                    catlog['Continuation-of'])
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7603
diff changeset
   299
        except Exception:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25748
diff changeset
   300
            raise error.Abort(_('could not parse cat-log of %s') % rev)
6037
dd3267698d84 convert: add full description for gnu arch revisions
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6035
diff changeset
   301
6049
348132c112cf convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6044
diff changeset
   302
    def _parsechangeset(self, data, rev):
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   303
        for l in data:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   304
            l = l.strip()
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   305
            # Added file (ignore added directory)
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   306
            if l.startswith('A') and not l.startswith('A/'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   307
                file = self._stripbasepath(l[1:].strip())
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   308
                if not self._exclude(file):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   309
                    self.changes[rev].add_files.append(file)
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   310
            # Deleted file (ignore deleted directory)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   311
            elif l.startswith('D') and not l.startswith('D/'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   312
                file = self._stripbasepath(l[1:].strip())
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   313
                if not self._exclude(file):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   314
                    self.changes[rev].del_files.append(file)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   315
            # Modified binary file
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   316
            elif l.startswith('Mb'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   317
                file = self._stripbasepath(l[2:].strip())
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   318
                if not self._exclude(file):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   319
                    self.changes[rev].mod_files.append(file)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   320
            # Modified link
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   321
            elif l.startswith('M->'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   322
                file = self._stripbasepath(l[3:].strip())
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   323
                if not self._exclude(file):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   324
                    self.changes[rev].mod_files.append(file)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   325
            # Modified file
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   326
            elif l.startswith('M'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   327
                file = self._stripbasepath(l[1:].strip())
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   328
                if not self._exclude(file):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   329
                    self.changes[rev].mod_files.append(file)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   330
            # Renamed file (or link)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   331
            elif l.startswith('=>'):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   332
                files = l[2:].strip().split(' ')
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   333
                if len(files) == 1:
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   334
                    files = l[2:].strip().split('\t')
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   335
                src = self._stripbasepath(files[0])
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   336
                dst = self._stripbasepath(files[1])
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   337
                if not self._exclude(src) and not self._exclude(dst):
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   338
                    self.changes[rev].ren_files[src] = dst
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   339
            # Conversion from file to link or from link to file (modified)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   340
            elif l.startswith('ch'):
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   341
                file = self._stripbasepath(l[2:].strip())
6055
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   342
                if not self._exclude(file):
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   343
                    self.changes[rev].mod_files.append(file)
a3d8b1f8721d convert: support binary files, link to files (viceversa) in gnu arch
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6049
diff changeset
   344
            # Renamed directory
6035
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   345
            elif l.startswith('/>'):
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   346
                dirs = l[2:].strip().split(' ')
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   347
                if len(dirs) == 1:
df659eb23360 convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
diff changeset
   348
                    dirs = l[2:].strip().split('\t')
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   349
                src = self._stripbasepath(dirs[0])
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   350
                dst = self._stripbasepath(dirs[1])
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   351
                if not self._exclude(src) and not self._exclude(dst):
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   352
                    self.changes[rev].ren_dirs[src] = dst