annotate hgfastimport/hgimport.py @ 52:38fe4f98a3ff

Use new utility function fastimport.processor.parseMany().
author Greg Ward <greg-hg@gerg.ca>
date Sun, 24 May 2009 10:53:02 -0400
parents ed66bd7bd2f6
children a88f0dd05e92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
1 # Copyright (C) 2008 Canonical Ltd
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
2 #
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
3 # This program is free software; you can redistribute it and/or modify
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
5 # the Free Software Foundation; either version 2 of the License, or
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
6 # (at your option) any later version.
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
7 #
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
8 # This program is distributed in the hope that it will be useful,
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
11 # GNU General Public License for more details.
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
12 #
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
14 # along with this program; if not, write to the Free Software
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
16
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
17 """Processor of import commands.
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
18
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
19 This module provides core processing functionality including an abstract class
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
20 for basing real processors on. See the processors package for examples.
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
21 """
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
22
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
23 import os
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
24 import shutil
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
25
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
26 from hgext.convert import common
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
27
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
28 from fastimport import processor, parser
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
29
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
30 class fastimport_source(common.converter_source):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
31 """Interface between the fastimport processor below and Mercurial's
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
32 normal conversion infrastructure.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
33 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
34 def __init__(self, ui, repo, sources):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
35 self.ui = ui
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
36 self.sources = sources
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
37 self.processor = HgImportProcessor(ui, repo)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
38 self.parsed = False
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
39
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
40 # converter_source methods
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
41
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
42 def before(self):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
43 self.processor.setup()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
44
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
45 def after(self):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
46 self.processor.teardown()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
48 def getheads(self):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
49 """Return a list of this repository's heads"""
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
50 self._parse()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
51 allheads = []
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
52 for branchheads in self.processor.branchmap.values():
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
53 allheads.extend(branchheads)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
54 return allheads
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
55
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
56 def getfile(self, name, fileid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
57 """Return file contents as a string. rev is the identifier returned
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
58 by a previous call to getchanges().
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
59 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
60 if fileid is None: # deleted file
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
61 raise IOError
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
62 return self.processor.getblob(fileid)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
63
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
64 def getmode(self, name, fileid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
65 """Return file mode, eg. '', 'x', or 'l'. rev is the identifier
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
66 returned by a previous call to getchanges().
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
67 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
68 return self.processor.getmode(name, fileid)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
69
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
70 def getchanges(self, commitid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
71 """Returns a tuple of (files, copies).
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
72
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
73 files is a sorted list of (filename, id) tuples for all files
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
74 changed between commitid and its first parent returned by
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
75 getcommit(). id is the source revision id of the file.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
76
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
77 copies is a dictionary of dest: source
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
78 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
79 return (self.processor.modified[commitid],
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
80 self.processor.copies[commitid])
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
81
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
82 def getcommit(self, commitid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
83 """Return the commit object for commitid"""
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
84 if commitid is None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
85 return None
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
86 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
87 return self.processor.commitmap[commitid]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
88
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
89 def gettags(self):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
90 """Return the tags as a dictionary of name: revision"""
49
ed66bd7bd2f6 comment
Greg Ward <greg-hg@gerg.ca>
parents: 48
diff changeset
91 # oops, this loses order
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
92 return dict(self.processor.tags)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
93
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
94 def getchangedfiles(self, rev, i):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
95 """Return the files changed by rev compared to parent[i].
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
96
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
97 i is an index selecting one of the parents of rev. The return
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
98 value should be the list of files that are different in rev and
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
99 this parent.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
100
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
101 If rev has no parents, i is None.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
102
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
103 This function is only needed to support --filemap
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
104 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
105 raise NotImplementedError()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
106
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
107 # private worker methods
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
108
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
109 def _parse(self):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
110 if self.parsed:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
111 return
52
38fe4f98a3ff Use new utility function fastimport.processor.parseMany().
Greg Ward <greg-hg@gerg.ca>
parents: 49
diff changeset
112 processor.parseMany(self.sources, parser.ImportParser, self.processor)
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
113 self.parsed = True
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
114
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
115 class HgImportProcessor(processor.ImportProcessor):
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
116
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
117 def __init__(self, ui, repo):
42
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
118 super(HgImportProcessor, self).__init__()
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
119 self.ui = ui
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
120 self.repo = repo
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
121
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
122 self.commitmap = {} # map commit ID (":1") to commit object
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
123 self.branchmap = {} # map branch name to list of heads
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
124
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
125 # see HgImportCommitHandler for details on these three
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
126 self.modified = {} # map commit id to list of file mods
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
127 self.filemodes = {} # map commit id to {filename: mode} map
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
128 self.copies = {} # map commit id to dict of file copies
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
129
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
130 self.tags = [] # list of (tag, mark) tuples
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
131
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
132 self.numblobs = 0 # for progress reporting
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
133 self.blobdir = None
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
134
34
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
135 def setup(self):
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
136 """Setup before processing any streams."""
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
137 pass
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
138
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
139 def teardown(self):
34
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
140 """Cleanup after processing all streams."""
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
141 if self.blobdir and os.path.exists(self.blobdir):
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
142 self.ui.status("Removing blob dir %r ...\n" % self.blobdir)
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
143 shutil.rmtree(self.blobdir)
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
144
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
145 def progress_handler(self, cmd):
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
146 self.ui.write("Progress: %s\n" % cmd.message)
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
147
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
148 def blob_handler(self, cmd):
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
149 self.writeblob(cmd.id, cmd.data)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
150
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
151 def _getblobfilename(self, blobid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
152 if self.blobdir is None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
153 raise RuntimeError("no blobs seen, so no blob directory created")
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
154 # XXX should escape ":" for windows
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
155 return os.path.join(self.blobdir, "blob-" + blobid)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
156
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
157 def getblob(self, fileid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
158 (commitid, blobid) = fileid
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
159 f = open(self._getblobfilename(blobid), "rb")
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
160 try:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
161 return f.read()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
162 finally:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
163 f.close()
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
164
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
165 def writeblob(self, blobid, data):
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
166 if self.blobdir is None: # no blobs seen yet
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
167 self.blobdir = os.path.join(self.repo.root, ".hg", "blobs")
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
168 os.mkdir(self.blobdir)
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
169
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
170 fn = self._getblobfilename(blobid)
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
171 blobfile = open(fn, "wb")
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
172 #self.ui.debug("writing blob %s to %s (%d bytes)\n"
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
173 # % (blobid, fn, len(data)))
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
174 blobfile.write(data)
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
175 blobfile.close()
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
176
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
177 self.numblobs += 1
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
178 if self.numblobs % 500 == 0:
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
179 self.ui.status("%d blobs read\n" % self.numblobs)
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
180
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
181 def getmode(self, name, fileid):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
182 (commitid, blobid) = fileid
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
183 return self.filemodes[commitid][name]
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
184
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
185 def checkpoint_handler(self, cmd):
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
186 # This command means nothing to us
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
187 pass
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
188
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
189 def _getcommit(self, committish):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
190 """Given a mark reference or a branch name, return the
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
191 appropriate commit object. Return None if committish is a
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
192 branch with no commits. Raises KeyError if anything else is out
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
193 of whack.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
194 """
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
195 if committish.startswith(":"):
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
196 # KeyError here indicates the input stream is broken.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
197 return self.commitmap[committish]
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
198 else:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
199 branch = self._getbranch(committish)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
200 if branch is None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
201 raise ValueError("invalid committish: %r" % committish)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
202
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
203 heads = self.branchmap.get(branch)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
204 if heads is None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
205 return None
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
206 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
207 # KeyError here indicates bad commit id in self.branchmap.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
208 return self.commitmap[heads[-1]]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
209
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
210 def _getbranch(self, ref):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
211 """Translate a Git head ref to corresponding Mercurial branch
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
212 name. E.g. \"refs/heads/foo\" is translated to \"foo\".
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
213 Special case: \"refs/heads/master\" becomes \"default\". If
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
214 'ref' is not a head ref, return None.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
215 """
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
216 prefix = "refs/heads/"
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
217 if ref.startswith(prefix):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
218 branch = ref[len(prefix):]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
219 if branch == "master":
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
220 return "default"
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
221 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
222 return branch
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
223 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
224 return None
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
225
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
226 def commit_handler(self, cmd):
39
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
227 # XXX this assumes the fixup branch name used by cvs2git. In
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
228 # contrast, git-fast-import(1) recommends "TAG_FIXUP" (not under
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
229 # refs/heads), and implies that it can be called whatever the
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
230 # creator of the fastimport dump wants to call it. So the name
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
231 # of the fixup branch should be configurable!
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
232 fixup = (cmd.ref == "refs/heads/TAG.FIXUP")
177a133519bc Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents: 37
diff changeset
233
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
234 if cmd.from_:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
235 first_parent = cmd.from_
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
236 else:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
237 first_parent = self._getcommit(cmd.ref) # commit object
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
238 if first_parent is not None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
239 first_parent = first_parent.rev # commit id
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
240
34
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
241 if cmd.merges:
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
242 if len(cmd.merges) > 1:
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
243 raise NotImplementedError("Can't handle more than two parents")
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
244 second_parent = cmd.merges[0]
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
245 else:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
246 second_parent = None
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
247
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
248 if first_parent is None and second_parent is not None:
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
249 # First commit on a new branch that has 'merge' but no 'from':
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
250 # special case meaning branch starts with no files; the contents of
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
251 # the first commit (this one) determine the list of files at branch
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
252 # time.
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
253 first_parent = second_parent
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
254 second_parent = None
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
255 no_files = True # XXX this is ignored...
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
256
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
257 self.ui.debug("commit %s: first_parent = %r, second_parent = %r\n"
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
258 % (cmd, first_parent, second_parent))
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
259 assert ((first_parent != second_parent) or
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
260 (first_parent is second_parent is None)), \
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
261 ("commit %s: first_parent == second parent = %r"
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
262 % (cmd, first_parent))
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
263
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
264 # Figure out the Mercurial branch name.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
265 if fixup and first_parent is not None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
266 # If this is a fixup commit, pretend it happened on the same
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
267 # branch as its first parent. (We don't want a Mercurial
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
268 # named branch called "TAG.FIXUP" in the output repository.)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
269 branch = self.commitmap[first_parent].branch
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
270 else:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
271 branch = self._getbranch(cmd.ref)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
272
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
273 commit_handler = HgImportCommitHandler(
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
274 self, cmd, self.ui)
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
275 commit_handler.process()
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
276 self.modified[cmd.id] = commit_handler.modified
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
277 self.filemodes[cmd.id] = commit_handler.mode
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
278 self.copies[cmd.id] = commit_handler.copies
16
234128693c29 Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents: 15
diff changeset
279
234128693c29 Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents: 15
diff changeset
280 # in case we are converting from git or bzr, prefer author but
234128693c29 Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents: 15
diff changeset
281 # fallback to committer (committer is required, author is
234128693c29 Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents: 15
diff changeset
282 # optional)
234128693c29 Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents: 15
diff changeset
283 userinfo = cmd.author or cmd.committer
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
284 if userinfo[0] == userinfo[1]:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
285 # In order to conform to fastimport syntax, cvs2git with no
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
286 # authormap produces author names like "jsmith <jsmith>"; if
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
287 # we see that, revert to plain old "jsmith".
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
288 user = userinfo[0]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
289 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
290 user = "%s <%s>" % (userinfo[0], userinfo[1])
34
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
291
37
513449a88de2 Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents: 34
diff changeset
292 assert type(cmd.message) is unicode
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
293 text = cmd.message.encode("utf-8")
34
08e2157aaa9a Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents: 33
diff changeset
294 date = self.convert_date(userinfo)
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
295
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
296 parents = filter(None, [first_parent, second_parent])
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
297 commit = common.commit(user, date, text, parents, branch, rev=cmd.id)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
298
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
299 self.commitmap[cmd.id] = commit
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
300 heads = self.branchmap.get(branch)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
301 if heads is None:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
302 heads = [cmd.id]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
303 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
304 # adding to an existing branch: replace the previous head
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
305 try:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
306 heads.remove(first_parent)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
307 except ValueError: # first parent not a head: no problem
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
308 pass
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
309 heads.append(cmd.id) # at end means this is tipmost
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
310 self.branchmap[branch] = heads
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
311 self.ui.debug("processed commit %s\n" % cmd)
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
312
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
313 def convert_date(self, c):
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
314 res = (int(c[2]), int(c[3]))
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
315 #print c, res
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
316 #print type((0, 0)), type(res), len(res), type(res) is type((0, 0))
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
317 #if type(res) is type((0, 0)) and len(res) == 2:
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
318 # print "go for it"
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
319 #return res
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
320 return "%d %d" % res
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
321
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
322 def reset_handler(self, cmd):
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
323 tagprefix = "refs/tags/"
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
324 branch = self._getbranch(cmd.ref)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
325 if branch:
42
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
326 # The usual case for 'reset': (re)create the named branch.
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
327 # XXX what should we do if cmd.from_ is None?
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
328 if cmd.from_ is not None:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
329 self.branchmap[branch] = [cmd.from_]
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
330 else:
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
331 # pretend the branch never existed... is this right?!?
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
332 try:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
333 del self.branchmap[branch]
44
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
334 except KeyError:
61ff7b929cea Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents: 43
diff changeset
335 pass
42
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
336 #else:
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
337 # # XXX filename? line number?
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
338 # self.ui.warn("ignoring branch reset with no 'from'\n")
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
339 elif cmd.ref.startswith(tagprefix):
42
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
340 # Create a "lightweight tag" in Git terms. As I understand
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
341 # it, that's a tag with no description and no history --
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
342 # rather like CVS tags. cvs2git turns CVS tags into Git
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
343 # lightweight tags, so we should make sure they become
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
344 # Mercurial tags. But we don't have to fake a history for
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
345 # them; save them up for the end.
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
346 tag = cmd.ref[len(tagprefix):]
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
347 self.tags.append((tag, cmd.from_))
15
e19d2ce18eeb Fix reset_handler
Paul Aurich <paul@darkrain42.org>
parents: 11
diff changeset
348
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
349 def tag_handler(self, cmd):
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
350 pass
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
351
42
71f1e5ed6213 Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents: 41
diff changeset
352
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
353 class HgImportCommitHandler(processor.CommitHandler):
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
354
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
355 def __init__(self, parent, command, ui):
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
356 self.parent = parent # HgImportProcessor running the show
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
357 self.command = command # CommitCommand that we're processing
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
358 self.ui = ui
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
359
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
360 # Files changes by this commit as a list of (filename, id)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
361 # tuples where id is (commitid, blobid). The blobid is
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
362 # needed to fetch the file's contents later, and the commitid
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
363 # is needed to fetch the mode.
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
364 # (XXX what about inline file contents?)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
365 # (XXX how to describe deleted files?)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
366 self.modified = []
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
367
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
368 # mode of files listed in self.modified: '', 'x', or 'l'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
369 self.mode = {}
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
370
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
371 # dictionary of src: dest (renamed files are in here and self.modified)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
372 self.copies = {}
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
373
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
374 # number of inline files seen in this commit
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
375 self.inlinecount = 0
1
9461f5c3a67c Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents: 0
diff changeset
376
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
377 def modify_handler(self, filecmd):
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
378 if filecmd.dataref:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
379 blobid = filecmd.dataref # blobid is the mark of the blob
11
9e9c215fcbd8 Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents: 10
diff changeset
380 else:
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
381 blobid = "%s-inline:%d" % (self.command.id, self.inlinecount)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
382 assert filecmd.data is not None
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
383 self.parent.writeblob(blobid, filecmd.data)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
384 self.inlinecount += 1
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
385
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
386 fileid = (self.command.id, blobid)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
387
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
388 self.modified.append((filecmd.path, fileid))
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
389 if filecmd.mode.endswith("644"): # normal file
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
390 mode = ''
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
391 elif filecmd.mode.endswith("755"): # executable
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
392 mode = 'x'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
393 elif filecmd.mode == "120000": # symlink
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
394 mode = 'l'
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
395 else:
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
396 raise RuntimeError("mode %r unsupported" % filecmd.mode)
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
397
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
398 self.mode[filecmd.path] = mode
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
399
3
24c600e5cb71 fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents: 1
diff changeset
400 def delete_handler(self, filecmd):
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
401 self.modified.append((filecmd.path, None))
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
402
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
403 def copy_handler(self, filecmd):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
404 self.copies[filecmd.src_path] = filecmd.dest_path
0
d107c6d36780 Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff changeset
405
47
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
406 def rename_handler(self, filecmd):
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
407 # copy oldname to newname and delete oldname
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
408 self.copies[filecmd.oldname] = filecmd.newname
7ff36dc9f0b1 Massive rework to use infrastructure provided by convert extension.
Greg Ward <greg-hg@gerg.ca>
parents: 46
diff changeset
409 self.files.append((filecmd.path, None))