Mercurial > hg > hg-fastimport
annotate hgfastimport/hgimport.py @ 44:61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Update test script to test real cvs2git output, not my idealized
version of it.
| author | Greg Ward <greg-hg@gerg.ca> |
|---|---|
| date | Mon, 11 May 2009 17:46:19 -0400 |
| parents | 000d4174071c |
| children | 93c2b1e832bd |
| 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 |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
24 import os.path |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
25 import errno |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
26 import shutil |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
27 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
28 import mercurial.hg |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
29 import mercurial.commands |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
30 from mercurial import util |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
31 from mercurial.node import nullrev, hex |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
32 |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
33 from fastimport import processor |
|
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
34 from hgfastimport import hgechoprocessor |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
35 |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
36 class HgImportProcessor(processor.ImportProcessor): |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
37 |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
38 def __init__(self, ui, repo, **opts): |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
39 super(HgImportProcessor, self).__init__() |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
40 self.ui = ui |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
41 self.repo = repo |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
42 self.opts = opts |
|
39
177a133519bc
Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents:
37
diff
changeset
|
43 self.last_commit = None # CommitCommand object |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
44 self.mark_map = {} # map mark (e.g. ":1") to revision number |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
45 self.branch_map = {} # map git branch name to revision number |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
46 self.lightweight_tags = [] # list of (ref, mark) tuples |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
47 |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
48 self.numblobs = 0 # for progress reporting |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
49 self.blobdir = None |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
50 |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
51 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
|
52 """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
|
53 pass |
|
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
54 |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
55 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
|
56 """Cleanup after processing all streams.""" |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
57 # Hmmm: this isn't really a cleanup step, it's a post-processing |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
58 # step. But we currently have one processor per input |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
59 # stream... despite the fact that state like mark_map, |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
60 # branch_map, and lightweight_tags really should span input |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
61 # streams. |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
62 self.write_lightweight_tags() |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
63 |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
64 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
|
65 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
|
66 shutil.rmtree(self.blobdir) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
67 |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
68 def progress_handler(self, cmd): |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
69 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
|
70 |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
71 def blob_handler(self, cmd): |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
72 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
|
73 # XXX cleanup? |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
74 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
|
75 os.mkdir(self.blobdir) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
76 |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
77 fn = self.getblobfilename(cmd.id) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
78 blobfile = open(fn, "wb") |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
79 #self.ui.debug("writing blob %s to %s (%d bytes)\n" |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
80 # % (cmd.id, fn, len(cmd.data))) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
81 blobfile.write(cmd.data) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
82 blobfile.close() |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
83 |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
84 self.numblobs += 1 |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
85 if self.numblobs % 500 == 0: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
86 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
|
87 |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
88 def getblobfilename(self, blobid): |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
89 if self.blobdir is None: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
90 raise RuntimeError("no blobs seen, so no blob directory created") |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
91 # XXX should escape ":" for windows |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
92 return os.path.join(self.blobdir, "blob-" + blobid) |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
93 |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
94 def checkpoint_handler(self, cmd): |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
95 # This command means nothing to us |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
96 pass |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
97 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
98 def committish_rev(self, committish): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
99 if committish.startswith(":"): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
100 return self.mark_map[committish] |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
101 else: |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
102 return self.branch_map[committish] |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
103 |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
104 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
|
105 # 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
|
106 # 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
|
107 # 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
|
108 # 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
|
109 # 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
|
110 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
|
111 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
112 if cmd.from_: |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
113 first_parent = self.committish_rev(cmd.from_) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
114 else: |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
115 first_parent = self.branch_map.get(cmd.ref, nullrev) |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
116 #self.ui.write("Bing\n") |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
117 if cmd.merges: |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
118 #self.ui.write("foo") |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
119 if len(cmd.merges) > 1: |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
120 raise NotImplementedError("Can't handle more than two parents") |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
121 second_parent = self.committish_rev(cmd.merges[0]) |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
122 #self.ui.write("Second parent: %s\n" % second_parent) |
|
44
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
123 else: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
124 second_parent = nullrev |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
125 |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
126 if first_parent is nullrev and second_parent is not nullrev: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
127 # 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
|
128 # 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
|
129 # 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
|
130 # time. |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
131 first_parent = second_parent |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
132 second_parent = nullrev |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
133 no_files = True # XXX not handled |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
134 |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
135 self.ui.debug("commit %s: first_parent = %r, second_parent = %r\n" |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
136 % (cmd.id, first_parent, second_parent)) |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
137 assert ((first_parent != second_parent) or |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
138 (first_parent == second_parent == -1)), \ |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
139 ("commit %s: first_parent == second parent = %r" |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
140 % (cmd.id, first_parent)) |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
141 |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
142 # Update to the first parent |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
143 mercurial.hg.clean(self.repo, self.repo.lookup(first_parent)) |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
144 mercurial.commands.debugsetparents( |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
145 self.ui, self.repo, first_parent, second_parent) |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
146 |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
147 #self.ui.write("Bing\n") |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
148 if cmd.ref == "refs/heads/master": |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
149 branch = "default" |
|
44
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
150 elif fixup and first_parent is not nullrev: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
151 # If this is a fixup commit, pretend it happened on the same branch |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
152 # as its first parent. (We don't want a Mercurial named branch |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
153 # called "TAG.FIXUP" in the output repository.) |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
154 branch = self.repo.changectx(first_parent).branch() |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
155 else: |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
156 branch = cmd.ref[len("refs/heads/"):] |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
157 #self.ui.write("Branch: %s\n" % branch) |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
158 self.repo.dirstate.setbranch(branch) |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
159 #self.ui.write("Bing\n") |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
160 #print "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
161 commit_handler = HgImportCommitHandler( |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
162 self, cmd, self.ui, self.repo, **self.opts) |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
163 commit_handler.process() |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
164 #print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
165 #self.ui.write(cmd.dump_str(verbose=True)) |
|
16
234128693c29
Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents:
15
diff
changeset
|
166 |
|
234128693c29
Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents:
15
diff
changeset
|
167 # 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
|
168 # 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
|
169 # optional) |
|
234128693c29
Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents:
15
diff
changeset
|
170 userinfo = cmd.author or cmd.committer |
|
234128693c29
Format the commit user as Full Name <user@example.com>
Paul Aurich <paul@darkrain42.org>
parents:
15
diff
changeset
|
171 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
|
172 |
|
37
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
173 # Blech: have to monkeypatch mercurial.encoding to ensure that |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
174 # everything under rawcommit() assumes the same encoding, |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
175 # regardless of current locale. |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
176 from mercurial import encoding |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
177 encoding.encoding = "UTF-8" |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
178 |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
179 files = commit_handler.filelist() |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
180 assert type(cmd.message) is unicode |
|
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
181 text = cmd.message.encode("utf-8") # XXX cmd.message is unicode |
|
34
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
182 date = self.convert_date(userinfo) |
|
08e2157aaa9a
Remove local fork of bzr-fastimport; use my fastimport library instead.
Greg Ward <greg-hg@gerg.ca>
parents:
33
diff
changeset
|
183 node = self.repo.rawcommit( |
|
37
513449a88de2
Handle non-ASCII input correctly (assuming UTF-8 encoding).
Greg Ward <greg-hg@gerg.ca>
parents:
34
diff
changeset
|
184 files=files, text=text, user=user, date=date) |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
185 rev = self.repo.changelog.rev(node) |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
186 if cmd.mark is not None: |
|
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
187 self.mark_map[":" + cmd.mark] = rev |
|
39
177a133519bc
Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents:
37
diff
changeset
|
188 if not fixup: |
|
177a133519bc
Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents:
37
diff
changeset
|
189 self.branch_map[cmd.ref] = rev |
|
177a133519bc
Handle fixup branches for tag/branch creation better.
Greg Ward <greg-hg@gerg.ca>
parents:
37
diff
changeset
|
190 self.last_commit = cmd |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
191 self.ui.write("Done commit of rev %d\n" % rev) |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
192 #self.ui.write("%s\n" % self.mark_map) |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
193 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
194 def convert_date(self, c): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
195 res = (int(c[2]), int(c[3])) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
196 #print c, res |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
197 #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
|
198 #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
|
199 # print "go for it" |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
200 #return res |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
201 return "%d %d" % res |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
202 |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
203 def reset_handler(self, cmd): |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
204 if cmd.ref.startswith("refs/heads/"): |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
205 # 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
|
206 # 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
|
207 if cmd.from_ is not None: |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
208 self.branch_map[cmd.ref] = self.committish_rev(cmd.from_) |
|
44
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
209 else: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
210 # 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
|
211 try: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
212 del self.branch_map[cmd.ref] |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
213 except KeyError: |
|
61ff7b929cea
Handle fixup commits and branch creation as produced by cvs2git.
Greg Ward <greg-hg@gerg.ca>
parents:
43
diff
changeset
|
214 pass |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
215 #else: |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
216 # # 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
|
217 # self.ui.warn("ignoring branch reset with no 'from'\n") |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
218 elif cmd.ref.startswith("refs/tags/"): |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
219 # 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
|
220 # 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
|
221 # 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
|
222 # 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
|
223 # 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
|
224 # them; save them up for the end. |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
225 self.lightweight_tags.append((cmd.ref, cmd.from_)) |
| 15 | 226 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
227 def tag_handler(self, cmd): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
228 pass |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
229 |
|
42
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
230 def write_lightweight_tags(self): |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
231 if not self.lightweight_tags: # avoid writing empty .hgtags |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
232 return |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
233 |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
234 # XXX what about duplicate tags? lightweight_tags is |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
235 # deliberately a list, to preserve order ... but do we need to |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
236 # worry about repeated tags? (Certainly not for cvs2git output, |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
237 # since CVS has no tag history.) |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
238 |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
239 # Create Mercurial tags from git-style "lightweight tags" in the |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
240 # input stream. |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
241 self.ui.status("updating tags\n") |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
242 mercurial.hg.clean(self.repo, self.repo.lookup("default")) |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
243 tagfile = open(self.repo.wjoin(".hgtags"), "ab") |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
244 for (ref, mark) in self.lightweight_tags: |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
245 tag = ref[len("refs/tags/"):] |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
246 rev = self.mark_map[mark] |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
247 node = self.repo.changelog.node(rev) |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
248 tagfile.write("%s %s\n" % (hex(node), tag)) |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
249 tagfile.close() |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
250 |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
251 files = [".hgtags"] |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
252 self.repo.rawcommit( |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
253 files=files, text="update tags", user="convert-repo", date=None) |
|
71f1e5ed6213
Convert "lightweight" tags, since that's how cvs2git handle CVS tags.
Greg Ward <greg-hg@gerg.ca>
parents:
41
diff
changeset
|
254 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
255 class HgImportCommitHandler(processor.CommitHandler): |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
256 |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
257 def __init__(self, parent, command, ui, repo, **opts): |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
258 self.parent = parent # HgImportProcessor running the show |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
259 self.command = command |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
260 self.ui = ui |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
261 self.repo = repo |
|
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
262 self.opts = opts |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
263 self.files = set() |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
264 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
265 def _make_container(self, path): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
266 if '/' in path: |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
267 d = os.path.dirname(path) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
268 if not os.path.isdir(d): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
269 os.makedirs(d) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
270 |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
271 def modify_handler(self, filecmd): |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
272 #print "============================" + filecmd.path |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
273 # FIXME: handle mode |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
274 self.files.add(filecmd.path) |
|
10
18c1e7ac0012
Fix so "hg -R <repo> fastimport ..." works
Greg Ward <greg-hg@gerg.ca>
parents:
3
diff
changeset
|
275 fullpath = os.path.join(self.repo.root, filecmd.path) |
|
18c1e7ac0012
Fix so "hg -R <repo> fastimport ..." works
Greg Ward <greg-hg@gerg.ca>
parents:
3
diff
changeset
|
276 self._make_container(fullpath) |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
277 #print "made dirs, writing file" |
|
11
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
278 if filecmd.dataref: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
279 # reference to a blob that has already appeared in the stream |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
280 fn = self.parent.getblobfilename(filecmd.dataref) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
281 if os.path.exists(fullpath): |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
282 os.remove(fullpath) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
283 try: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
284 os.link(fn, fullpath) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
285 except OSError, err: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
286 if err.errno == errno.ENOENT: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
287 # if this happens, it's a problem in the fast-import |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
288 # stream |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
289 raise util.Abort("bad blob ref %r (no such file %s)" |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
290 % (filecmd.dataref, fn)) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
291 else: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
292 # anything else is a bug in this extension |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
293 # (cross-device move, permissions, etc.) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
294 raise |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
295 elif filecmd.data: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
296 f = open(fullpath, "w") |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
297 f.write(filecmd.data) |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
298 f.close() |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
299 else: |
|
9e9c215fcbd8
Handle blobs in the fast-import stream.
Greg Ward <greg-hg@gerg.ca>
parents:
10
diff
changeset
|
300 raise RuntimeError("either filecmd.dataref or filecmd.data must be set") |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
301 #print self.repo.add([filecmd.path]) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
302 #print "Done:", filecmd.path |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
303 |
|
3
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
304 def delete_handler(self, filecmd): |
|
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
305 self.files.add(filecmd.path) |
|
24c600e5cb71
fixes to file deletes, second parents, mark handling
Paul Crowley <paul@lshift.net>
parents:
1
diff
changeset
|
306 self.repo.remove([filecmd.path], unlink=True) |
|
0
d107c6d36780
Add the start of the hg fastimport command
Paul Crowley <paul@lshift.net>
parents:
diff
changeset
|
307 |
|
1
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
308 #def copy_handler(self, filecmd): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
309 # self.files.add(filecmd.path) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
310 # """Handle a filecopy command.""" |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
311 # self.ui.write("Cmd: %s\n" % repr(filecmd)) |
|
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 rename_handler(self, filecmd): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
314 # self.files.add(filecmd.path) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
315 # """Handle a filerename command.""" |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
316 # self.ui.write("Cmd: %s\n" % repr(filecmd)) |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
317 |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
318 def filelist(self): |
|
9461f5c3a67c
Actually imports something - incredible!
Paul Crowley <paul@lshift.net>
parents:
0
diff
changeset
|
319 return list(self.files) |
