Show More
@@ -1,298 +1,303 b'' | |||
|
1 | 1 | # git.py - git support for the convert extension |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | import os |
|
9 | 9 | import subprocess |
|
10 | 10 | from mercurial import util, config |
|
11 | 11 | from mercurial.node import hex, nullid |
|
12 | 12 | from mercurial.i18n import _ |
|
13 | 13 | |
|
14 | 14 | from common import NoRepo, commit, converter_source, checktool |
|
15 | 15 | |
|
16 | 16 | class submodule(object): |
|
17 | 17 | def __init__(self, path, node, url): |
|
18 | 18 | self.path = path |
|
19 | 19 | self.node = node |
|
20 | 20 | self.url = url |
|
21 | 21 | |
|
22 | 22 | def hgsub(self): |
|
23 | 23 | return "%s = [git]%s" % (self.path, self.url) |
|
24 | 24 | |
|
25 | 25 | def hgsubstate(self): |
|
26 | 26 | return "%s %s" % (self.node, self.path) |
|
27 | 27 | |
|
28 | 28 | class convert_git(converter_source): |
|
29 | 29 | # Windows does not support GIT_DIR= construct while other systems |
|
30 | 30 | # cannot remove environment variable. Just assume none have |
|
31 | 31 | # both issues. |
|
32 | 32 | if util.safehasattr(os, 'unsetenv'): |
|
33 | 33 | def gitopen(self, s, err=None): |
|
34 | 34 | prevgitdir = os.environ.get('GIT_DIR') |
|
35 | 35 | os.environ['GIT_DIR'] = self.path |
|
36 | 36 | try: |
|
37 | 37 | if err == subprocess.PIPE: |
|
38 | 38 | (stdin, stdout, stderr) = util.popen3(s) |
|
39 | 39 | return stdout |
|
40 | 40 | elif err == subprocess.STDOUT: |
|
41 | 41 | return self.popen_with_stderr(s) |
|
42 | 42 | else: |
|
43 | 43 | return util.popen(s, 'rb') |
|
44 | 44 | finally: |
|
45 | 45 | if prevgitdir is None: |
|
46 | 46 | del os.environ['GIT_DIR'] |
|
47 | 47 | else: |
|
48 | 48 | os.environ['GIT_DIR'] = prevgitdir |
|
49 | 49 | else: |
|
50 | 50 | def gitopen(self, s, err=None): |
|
51 | 51 | if err == subprocess.PIPE: |
|
52 | 52 | (sin, so, se) = util.popen3('GIT_DIR=%s %s' % (self.path, s)) |
|
53 | 53 | return so |
|
54 | 54 | elif err == subprocess.STDOUT: |
|
55 | 55 | return self.popen_with_stderr(s) |
|
56 | 56 | else: |
|
57 | 57 | return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb') |
|
58 | 58 | |
|
59 | 59 | def popen_with_stderr(self, s): |
|
60 | 60 | p = subprocess.Popen(s, shell=True, bufsize=-1, |
|
61 | 61 | close_fds=util.closefds, |
|
62 | 62 | stdin=subprocess.PIPE, |
|
63 | 63 | stdout=subprocess.PIPE, |
|
64 | 64 | stderr=subprocess.STDOUT, |
|
65 | 65 | universal_newlines=False, |
|
66 | 66 | env=None) |
|
67 | 67 | return p.stdout |
|
68 | 68 | |
|
69 | 69 | def gitread(self, s): |
|
70 | 70 | fh = self.gitopen(s) |
|
71 | 71 | data = fh.read() |
|
72 | 72 | return data, fh.close() |
|
73 | 73 | |
|
74 | 74 | def __init__(self, ui, path, rev=None): |
|
75 | 75 | super(convert_git, self).__init__(ui, path, rev=rev) |
|
76 | 76 | |
|
77 | 77 | if os.path.isdir(path + "/.git"): |
|
78 | 78 | path += "/.git" |
|
79 | 79 | if not os.path.exists(path + "/objects"): |
|
80 | 80 | raise NoRepo(_("%s does not look like a Git repository") % path) |
|
81 | 81 | |
|
82 | 82 | checktool('git', 'git') |
|
83 | 83 | |
|
84 | 84 | self.path = path |
|
85 | 85 | self.submodules = [] |
|
86 | 86 | |
|
87 | 87 | def getheads(self): |
|
88 | 88 | if not self.rev: |
|
89 | 89 | heads, ret = self.gitread('git rev-parse --branches --remotes') |
|
90 | 90 | heads = heads.splitlines() |
|
91 | 91 | else: |
|
92 | 92 | heads, ret = self.gitread("git rev-parse --verify %s" % self.rev) |
|
93 | 93 | heads = [heads[:-1]] |
|
94 | 94 | if ret: |
|
95 | 95 | raise util.Abort(_('cannot retrieve git heads')) |
|
96 | 96 | return heads |
|
97 | 97 | |
|
98 | 98 | def catfile(self, rev, type): |
|
99 | 99 | if rev == hex(nullid): |
|
100 | 100 | raise IOError |
|
101 | 101 | data, ret = self.gitread("git cat-file %s %s" % (type, rev)) |
|
102 | 102 | if ret: |
|
103 | 103 | raise util.Abort(_('cannot read %r object at %s') % (type, rev)) |
|
104 | 104 | return data |
|
105 | 105 | |
|
106 | 106 | def getfile(self, name, rev): |
|
107 | 107 | if name == '.hgsub': |
|
108 | 108 | data = '\n'.join([m.hgsub() for m in self.submoditer()]) |
|
109 | 109 | mode = '' |
|
110 | 110 | elif name == '.hgsubstate': |
|
111 | 111 | data = '\n'.join([m.hgsubstate() for m in self.submoditer()]) |
|
112 | 112 | mode = '' |
|
113 | 113 | else: |
|
114 | 114 | data = self.catfile(rev, "blob") |
|
115 | 115 | mode = self.modecache[(name, rev)] |
|
116 | 116 | return data, mode |
|
117 | 117 | |
|
118 | 118 | def submoditer(self): |
|
119 | 119 | null = hex(nullid) |
|
120 | 120 | for m in sorted(self.submodules, key=lambda p: p.path): |
|
121 | 121 | if m.node != null: |
|
122 | 122 | yield m |
|
123 | 123 | |
|
124 | 124 | def parsegitmodules(self, content): |
|
125 | 125 | """Parse the formatted .gitmodules file, example file format: |
|
126 | 126 | [submodule "sub"]\n |
|
127 | 127 | \tpath = sub\n |
|
128 | 128 | \turl = git://giturl\n |
|
129 | 129 | """ |
|
130 | 130 | self.submodules = [] |
|
131 | 131 | c = config.config() |
|
132 | 132 | # Each item in .gitmodules starts with \t that cant be parsed |
|
133 | 133 | c.parse('.gitmodules', content.replace('\t','')) |
|
134 | 134 | for sec in c.sections(): |
|
135 | 135 | s = c[sec] |
|
136 | 136 | if 'url' in s and 'path' in s: |
|
137 | 137 | self.submodules.append(submodule(s['path'], '', s['url'])) |
|
138 | 138 | |
|
139 | 139 | def retrievegitmodules(self, version): |
|
140 | 140 | modules, ret = self.gitread("git show %s:%s" % (version, '.gitmodules')) |
|
141 | 141 | if ret: |
|
142 | 142 | raise util.Abort(_('cannot read submodules config file in %s') % |
|
143 | 143 | version) |
|
144 | 144 | self.parsegitmodules(modules) |
|
145 | 145 | for m in self.submodules: |
|
146 | 146 | node, ret = self.gitread("git rev-parse %s:%s" % (version, m.path)) |
|
147 | 147 | if ret: |
|
148 | 148 | continue |
|
149 | 149 | m.node = node.strip() |
|
150 | 150 | |
|
151 | 151 | def getchanges(self, version): |
|
152 | 152 | self.modecache = {} |
|
153 | 153 | fh = self.gitopen("git diff-tree -z --root -m -r %s" % version) |
|
154 | 154 | changes = [] |
|
155 | 155 | seen = set() |
|
156 | 156 | entry = None |
|
157 | 157 | subexists = False |
|
158 | 158 | for l in fh.read().split('\x00'): |
|
159 | 159 | if not entry: |
|
160 | 160 | if not l.startswith(':'): |
|
161 | 161 | continue |
|
162 | 162 | entry = l |
|
163 | 163 | continue |
|
164 | 164 | f = l |
|
165 | 165 | if f not in seen: |
|
166 | 166 | seen.add(f) |
|
167 | 167 | entry = entry.split() |
|
168 | 168 | h = entry[3] |
|
169 | 169 | p = (entry[1] == "100755") |
|
170 | 170 | s = (entry[1] == "120000") |
|
171 | 171 | |
|
172 | 172 | if f == '.gitmodules': |
|
173 | 173 | subexists = True |
|
174 | 174 | changes.append(('.hgsub', '')) |
|
175 | 175 | elif entry[1] == '160000' or entry[0] == ':160000': |
|
176 | 176 | subexists = True |
|
177 | 177 | else: |
|
178 | 178 | self.modecache[(f, h)] = (p and "x") or (s and "l") or "" |
|
179 | 179 | changes.append((f, h)) |
|
180 | 180 | entry = None |
|
181 | 181 | if fh.close(): |
|
182 | 182 | raise util.Abort(_('cannot read changes in %s') % version) |
|
183 | 183 | |
|
184 | 184 | if subexists: |
|
185 | 185 | self.retrievegitmodules(version) |
|
186 | 186 | changes.append(('.hgsubstate', '')) |
|
187 | 187 | return (changes, {}) |
|
188 | 188 | |
|
189 | 189 | def getcommit(self, version): |
|
190 | 190 | c = self.catfile(version, "commit") # read the commit hash |
|
191 | 191 | end = c.find("\n\n") |
|
192 | 192 | message = c[end + 2:] |
|
193 | 193 | message = self.recode(message) |
|
194 | 194 | l = c[:end].splitlines() |
|
195 | 195 | parents = [] |
|
196 | 196 | author = committer = None |
|
197 | 197 | for e in l[1:]: |
|
198 | 198 | n, v = e.split(" ", 1) |
|
199 | 199 | if n == "author": |
|
200 | 200 | p = v.split() |
|
201 | 201 | tm, tz = p[-2:] |
|
202 | 202 | author = " ".join(p[:-2]) |
|
203 | 203 | if author[0] == "<": author = author[1:-1] |
|
204 | 204 | author = self.recode(author) |
|
205 | 205 | if n == "committer": |
|
206 | 206 | p = v.split() |
|
207 | 207 | tm, tz = p[-2:] |
|
208 | 208 | committer = " ".join(p[:-2]) |
|
209 | 209 | if committer[0] == "<": committer = committer[1:-1] |
|
210 | 210 | committer = self.recode(committer) |
|
211 | 211 | if n == "parent": |
|
212 | 212 | parents.append(v) |
|
213 | 213 | |
|
214 | 214 | if committer and committer != author: |
|
215 | 215 | message += "\ncommitter: %s\n" % committer |
|
216 | 216 | tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
|
217 | 217 | tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
|
218 | 218 | date = tm + " " + str(tz) |
|
219 | 219 | |
|
220 | 220 | c = commit(parents=parents, date=date, author=author, desc=message, |
|
221 | 221 | rev=version) |
|
222 | 222 | return c |
|
223 | 223 | |
|
224 | 224 | def gettags(self): |
|
225 | 225 | tags = {} |
|
226 | 226 | alltags = {} |
|
227 | 227 | fh = self.gitopen('git ls-remote --tags "%s"' % self.path, |
|
228 | 228 | err=subprocess.STDOUT) |
|
229 | 229 | prefix = 'refs/tags/' |
|
230 | 230 | |
|
231 | 231 | # Build complete list of tags, both annotated and bare ones |
|
232 | 232 | for line in fh: |
|
233 | 233 | line = line.strip() |
|
234 | 234 | if line.startswith("error:") or line.startswith("fatal:"): |
|
235 | 235 | raise util.Abort(_('cannot read tags from %s') % self.path) |
|
236 | 236 | node, tag = line.split(None, 1) |
|
237 | 237 | if not tag.startswith(prefix): |
|
238 | 238 | continue |
|
239 | 239 | alltags[tag[len(prefix):]] = node |
|
240 | 240 | if fh.close(): |
|
241 | 241 | raise util.Abort(_('cannot read tags from %s') % self.path) |
|
242 | 242 | |
|
243 | 243 | # Filter out tag objects for annotated tag refs |
|
244 | 244 | for tag in alltags: |
|
245 | 245 | if tag.endswith('^{}'): |
|
246 | 246 | tags[tag[:-3]] = alltags[tag] |
|
247 | 247 | else: |
|
248 | 248 | if tag + '^{}' in alltags: |
|
249 | 249 | continue |
|
250 | 250 | else: |
|
251 | 251 | tags[tag] = alltags[tag] |
|
252 | 252 | |
|
253 | 253 | return tags |
|
254 | 254 | |
|
255 | 255 | def getchangedfiles(self, version, i): |
|
256 | 256 | changes = [] |
|
257 | 257 | if i is None: |
|
258 | 258 | fh = self.gitopen("git diff-tree --root -m -r %s" % version) |
|
259 | 259 | for l in fh: |
|
260 | 260 | if "\t" not in l: |
|
261 | 261 | continue |
|
262 | 262 | m, f = l[:-1].split("\t") |
|
263 | 263 | changes.append(f) |
|
264 | 264 | else: |
|
265 | 265 | fh = self.gitopen('git diff-tree --name-only --root -r %s ' |
|
266 | 266 | '"%s^%s" --' % (version, version, i + 1)) |
|
267 | 267 | changes = [f.rstrip('\n') for f in fh] |
|
268 | 268 | if fh.close(): |
|
269 | 269 | raise util.Abort(_('cannot read changes in %s') % version) |
|
270 | 270 | |
|
271 | 271 | return changes |
|
272 | 272 | |
|
273 | 273 | def getbookmarks(self): |
|
274 | 274 | bookmarks = {} |
|
275 | 275 | |
|
276 | 276 | # Interesting references in git are prefixed |
|
277 | 277 | prefix = 'refs/heads/' |
|
278 | 278 | prefixlen = len(prefix) |
|
279 | 279 | |
|
280 | 280 | # factor two commands |
|
281 | 281 | gitcmd = { 'remote/': 'git ls-remote --heads origin', |
|
282 | 282 | '': 'git show-ref'} |
|
283 | 283 | |
|
284 | 284 | # Origin heads |
|
285 | 285 | for reftype in gitcmd: |
|
286 | 286 | try: |
|
287 | 287 | fh = self.gitopen(gitcmd[reftype], err=subprocess.PIPE) |
|
288 | 288 | for line in fh: |
|
289 | 289 | line = line.strip() |
|
290 | 290 | rev, name = line.split(None, 1) |
|
291 | 291 | if not name.startswith(prefix): |
|
292 | 292 | continue |
|
293 | 293 | name = '%s%s' % (reftype, name[prefixlen:]) |
|
294 | 294 | bookmarks[name] = rev |
|
295 | 295 | except Exception: |
|
296 | 296 | pass |
|
297 | 297 | |
|
298 | 298 | return bookmarks |
|
299 | ||
|
300 | def checkrevformat(self, revstr): | |
|
301 | """ git revision string is a 40 byte hex """ | |
|
302 | self.checkhexformat(revstr) | |
|
303 |
@@ -1,358 +1,392 b'' | |||
|
1 | 1 | |
|
2 | 2 | $ "$TESTDIR/hghave" git || exit 80 |
|
3 | 3 | $ echo "[core]" >> $HOME/.gitconfig |
|
4 | 4 | $ echo "autocrlf = false" >> $HOME/.gitconfig |
|
5 | 5 | $ echo "[core]" >> $HOME/.gitconfig |
|
6 | 6 | $ echo "autocrlf = false" >> $HOME/.gitconfig |
|
7 | 7 | $ echo "[extensions]" >> $HGRCPATH |
|
8 | 8 | $ echo "convert=" >> $HGRCPATH |
|
9 | 9 | $ echo 'hgext.graphlog =' >> $HGRCPATH |
|
10 | 10 | $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME |
|
11 | 11 | $ GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL |
|
12 | 12 | $ GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE |
|
13 | 13 | $ GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME |
|
14 | 14 | $ GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL |
|
15 | 15 | $ GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE |
|
16 | $ INVALIDID1=afd12345af | |
|
17 | $ INVALIDID2=28173x36ddd1e67bf7098d541130558ef5534a86 | |
|
18 | $ VALIDID1=39b3d83f9a69a9ba4ebb111461071a0af0027357 | |
|
19 | $ VALIDID2=8dd6476bd09d9c7776355dc454dafe38efaec5da | |
|
16 | 20 |
$ |
|
17 | 21 | $ commit() |
|
18 | 22 | > { |
|
19 | 23 | > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000" |
|
20 | 24 | > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" |
|
21 | 25 | > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error" |
|
22 | 26 | > count=`expr $count + 1` |
|
23 | 27 | > } |
|
24 | 28 | $ mkdir git-repo |
|
25 | 29 | $ cd git-repo |
|
26 | 30 | $ git init-db >/dev/null 2>/dev/null |
|
27 | 31 | $ echo a > a |
|
28 | 32 | $ mkdir d |
|
29 | 33 | $ echo b > d/b |
|
30 | 34 | $ git add a d |
|
31 | 35 | $ commit -a -m t1 |
|
32 | 36 | |
|
33 | 37 | Remove the directory, then try to replace it with a file |
|
34 | 38 | (issue 754) |
|
35 | 39 | |
|
36 | 40 | $ git rm -f d/b |
|
37 | 41 | rm 'd/b' |
|
38 | 42 | $ commit -m t2 |
|
39 | 43 | $ echo d > d |
|
40 | 44 | $ git add d |
|
41 | 45 | $ commit -m t3 |
|
42 | 46 | $ echo b >> a |
|
43 | 47 | $ commit -a -m t4.1 |
|
44 | 48 | $ git checkout -b other HEAD~ >/dev/null 2>/dev/null |
|
45 | 49 | $ echo c > a |
|
46 | 50 | $ echo a >> a |
|
47 | 51 | $ commit -a -m t4.2 |
|
48 | 52 | $ git checkout master >/dev/null 2>/dev/null |
|
49 | 53 | $ git pull --no-commit . other > /dev/null 2>/dev/null |
|
50 | 54 | $ commit -m 'Merge branch other' |
|
51 | 55 | $ cd .. |
|
52 | 56 | $ hg convert --datesort git-repo |
|
53 | 57 | assuming destination git-repo-hg |
|
54 | 58 | initializing destination git-repo-hg repository |
|
55 | 59 | scanning source... |
|
56 | 60 | sorting... |
|
57 | 61 | converting... |
|
58 | 62 | 5 t1 |
|
59 | 63 | 4 t2 |
|
60 | 64 | 3 t3 |
|
61 | 65 | 2 t4.1 |
|
62 | 66 | 1 t4.2 |
|
63 | 67 | 0 Merge branch other |
|
64 | 68 | updating bookmarks |
|
65 | 69 | $ hg up -q -R git-repo-hg |
|
66 | 70 | $ hg -R git-repo-hg tip -v |
|
67 | 71 | changeset: 5:c78094926be2 |
|
68 | 72 | bookmark: master |
|
69 | 73 | tag: tip |
|
70 | 74 | parent: 3:f5f5cb45432b |
|
71 | 75 | parent: 4:4e174f80c67c |
|
72 | 76 | user: test <test@example.org> |
|
73 | 77 | date: Mon Jan 01 00:00:15 2007 +0000 |
|
74 | 78 | files: a |
|
75 | 79 | description: |
|
76 | 80 | Merge branch other |
|
77 | 81 | |
|
78 | 82 | |
|
79 | 83 | $ count=10 |
|
80 | 84 | $ mkdir git-repo2 |
|
81 | 85 | $ cd git-repo2 |
|
82 | 86 | $ git init-db >/dev/null 2>/dev/null |
|
83 | 87 | $ echo foo > foo |
|
84 | 88 | $ git add foo |
|
85 | 89 | $ commit -a -m 'add foo' |
|
86 | 90 | $ echo >> foo |
|
87 | 91 | $ commit -a -m 'change foo' |
|
88 | 92 | $ git checkout -b Bar HEAD~ >/dev/null 2>/dev/null |
|
89 | 93 | $ echo quux >> quux |
|
90 | 94 | $ git add quux |
|
91 | 95 | $ commit -a -m 'add quux' |
|
92 | 96 | $ echo bar > bar |
|
93 | 97 | $ git add bar |
|
94 | 98 | $ commit -a -m 'add bar' |
|
95 | 99 | $ git checkout -b Baz HEAD~ >/dev/null 2>/dev/null |
|
96 | 100 | $ echo baz > baz |
|
97 | 101 | $ git add baz |
|
98 | 102 | $ commit -a -m 'add baz' |
|
99 | 103 | $ git checkout master >/dev/null 2>/dev/null |
|
100 | 104 | $ git pull --no-commit . Bar Baz > /dev/null 2>/dev/null |
|
101 | 105 | $ commit -m 'Octopus merge' |
|
102 | 106 | $ echo bar >> bar |
|
103 | 107 | $ commit -a -m 'change bar' |
|
104 | 108 | $ git checkout -b Foo HEAD~ >/dev/null 2>/dev/null |
|
105 | 109 | $ echo >> foo |
|
106 | 110 | $ commit -a -m 'change foo' |
|
107 | 111 | $ git checkout master >/dev/null 2>/dev/null |
|
108 | 112 | $ git pull --no-commit -s ours . Foo > /dev/null 2>/dev/null |
|
109 | 113 | $ commit -m 'Discard change to foo' |
|
110 | 114 | $ cd .. |
|
111 | 115 | $ glog() |
|
112 | 116 | > { |
|
113 | 117 | > hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@" |
|
114 | 118 | > } |
|
115 | 119 | $ splitrepo() |
|
116 | 120 | > { |
|
117 | 121 | > msg="$1" |
|
118 | 122 | > files="$2" |
|
119 | 123 | > opts=$3 |
|
120 | 124 | > echo "% $files: $msg" |
|
121 | 125 | > prefix=`echo "$files" | sed -e 's/ /-/g'` |
|
122 | 126 | > fmap="$prefix.fmap" |
|
123 | 127 | > repo="$prefix.repo" |
|
124 | 128 | > for i in $files; do |
|
125 | 129 | > echo "include $i" >> "$fmap" |
|
126 | 130 | > done |
|
127 | 131 | > hg -q convert $opts --filemap "$fmap" --datesort git-repo2 "$repo" |
|
128 | 132 | > hg up -q -R "$repo" |
|
129 | 133 | > glog -R "$repo" |
|
130 | 134 | > hg -R "$repo" manifest --debug |
|
131 | 135 | > } |
|
132 | 136 | |
|
133 | 137 | full conversion |
|
134 | 138 | |
|
135 | 139 | $ hg -q convert --datesort git-repo2 fullrepo |
|
136 | 140 | $ hg up -q -R fullrepo |
|
137 | 141 | $ glog -R fullrepo |
|
138 | 142 | @ 9 "Discard change to foo" files: foo |
|
139 | 143 | |\ |
|
140 | 144 | | o 8 "change foo" files: foo |
|
141 | 145 | | | |
|
142 | 146 | o | 7 "change bar" files: bar |
|
143 | 147 | |/ |
|
144 | 148 | o 6 "(octopus merge fixup)" files: |
|
145 | 149 | |\ |
|
146 | 150 | | o 5 "Octopus merge" files: baz |
|
147 | 151 | | |\ |
|
148 | 152 | o | | 4 "add baz" files: baz |
|
149 | 153 | | | | |
|
150 | 154 | +---o 3 "add bar" files: bar |
|
151 | 155 | | | |
|
152 | 156 | o | 2 "add quux" files: quux |
|
153 | 157 | | | |
|
154 | 158 | | o 1 "change foo" files: foo |
|
155 | 159 | |/ |
|
156 | 160 | o 0 "add foo" files: foo |
|
157 | 161 | |
|
158 | 162 | $ hg -R fullrepo manifest --debug |
|
159 | 163 | 245a3b8bc653999c2b22cdabd517ccb47aecafdf 644 bar |
|
160 | 164 | 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz |
|
161 | 165 | 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo |
|
162 | 166 | 88dfeab657e8cf2cef3dec67b914f49791ae76b1 644 quux |
|
163 | 167 | $ splitrepo 'octopus merge' 'foo bar baz' |
|
164 | 168 | % foo bar baz: octopus merge |
|
165 | 169 | @ 8 "Discard change to foo" files: foo |
|
166 | 170 | |\ |
|
167 | 171 | | o 7 "change foo" files: foo |
|
168 | 172 | | | |
|
169 | 173 | o | 6 "change bar" files: bar |
|
170 | 174 | |/ |
|
171 | 175 | o 5 "(octopus merge fixup)" files: |
|
172 | 176 | |\ |
|
173 | 177 | | o 4 "Octopus merge" files: baz |
|
174 | 178 | | |\ |
|
175 | 179 | o | | 3 "add baz" files: baz |
|
176 | 180 | | | | |
|
177 | 181 | +---o 2 "add bar" files: bar |
|
178 | 182 | | | |
|
179 | 183 | | o 1 "change foo" files: foo |
|
180 | 184 | |/ |
|
181 | 185 | o 0 "add foo" files: foo |
|
182 | 186 | |
|
183 | 187 | 245a3b8bc653999c2b22cdabd517ccb47aecafdf 644 bar |
|
184 | 188 | 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz |
|
185 | 189 | 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo |
|
186 | 190 | $ splitrepo 'only some parents of an octopus merge; "discard" a head' 'foo baz quux' |
|
187 | 191 | % foo baz quux: only some parents of an octopus merge; "discard" a head |
|
188 | 192 | @ 6 "Discard change to foo" files: foo |
|
189 | 193 | | |
|
190 | 194 | o 5 "change foo" files: foo |
|
191 | 195 | | |
|
192 | 196 | o 4 "Octopus merge" files: |
|
193 | 197 | |\ |
|
194 | 198 | | o 3 "add baz" files: baz |
|
195 | 199 | | | |
|
196 | 200 | | o 2 "add quux" files: quux |
|
197 | 201 | | | |
|
198 | 202 | o | 1 "change foo" files: foo |
|
199 | 203 | |/ |
|
200 | 204 | o 0 "add foo" files: foo |
|
201 | 205 | |
|
202 | 206 | 354ae8da6e890359ef49ade27b68bbc361f3ca88 644 baz |
|
203 | 207 | 9277c9cc8dd4576fc01a17939b4351e5ada93466 644 foo |
|
204 | 208 | 88dfeab657e8cf2cef3dec67b914f49791ae76b1 644 quux |
|
205 | 209 | |
|
206 | 210 | test binary conversion (issue 1359) |
|
207 | 211 | |
|
208 | 212 | $ mkdir git-repo3 |
|
209 | 213 | $ cd git-repo3 |
|
210 | 214 | $ git init-db >/dev/null 2>/dev/null |
|
211 | 215 | $ python -c 'file("b", "wb").write("".join([chr(i) for i in range(256)])*16)' |
|
212 | 216 | $ git add b |
|
213 | 217 | $ commit -a -m addbinary |
|
214 | 218 | $ cd .. |
|
215 | 219 | |
|
216 | 220 | convert binary file |
|
217 | 221 | |
|
218 | 222 | $ hg convert git-repo3 git-repo3-hg |
|
219 | 223 | initializing destination git-repo3-hg repository |
|
220 | 224 | scanning source... |
|
221 | 225 | sorting... |
|
222 | 226 | converting... |
|
223 | 227 | 0 addbinary |
|
224 | 228 | updating bookmarks |
|
225 | 229 | $ cd git-repo3-hg |
|
226 | 230 | $ hg up -C |
|
227 | 231 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
228 | 232 | $ python -c 'print len(file("b", "rb").read())' |
|
229 | 233 | 4096 |
|
230 | 234 | $ cd .. |
|
231 | 235 | |
|
232 | 236 | test author vs committer |
|
233 | 237 | |
|
234 | 238 | $ mkdir git-repo4 |
|
235 | 239 | $ cd git-repo4 |
|
236 | 240 | $ git init-db >/dev/null 2>/dev/null |
|
237 | 241 | $ echo >> foo |
|
238 | 242 | $ git add foo |
|
239 | 243 | $ commit -a -m addfoo |
|
240 | 244 | $ echo >> foo |
|
241 | 245 | $ GIT_AUTHOR_NAME="nottest" |
|
242 | 246 | $ commit -a -m addfoo2 |
|
243 | 247 | $ cd .. |
|
244 | 248 | |
|
245 | 249 | convert author committer |
|
246 | 250 | |
|
247 | 251 | $ hg convert git-repo4 git-repo4-hg |
|
248 | 252 | initializing destination git-repo4-hg repository |
|
249 | 253 | scanning source... |
|
250 | 254 | sorting... |
|
251 | 255 | converting... |
|
252 | 256 | 1 addfoo |
|
253 | 257 | 0 addfoo2 |
|
254 | 258 | updating bookmarks |
|
255 | 259 | $ hg -R git-repo4-hg log -v |
|
256 | 260 | changeset: 1:d63e967f93da |
|
257 | 261 | bookmark: master |
|
258 | 262 | tag: tip |
|
259 | 263 | user: nottest <test@example.org> |
|
260 | 264 | date: Mon Jan 01 00:00:21 2007 +0000 |
|
261 | 265 | files: foo |
|
262 | 266 | description: |
|
263 | 267 | addfoo2 |
|
264 | 268 | |
|
265 | 269 | committer: test <test@example.org> |
|
266 | 270 | |
|
267 | 271 | |
|
268 | 272 | changeset: 0:0735477b0224 |
|
269 | 273 | user: test <test@example.org> |
|
270 | 274 | date: Mon Jan 01 00:00:20 2007 +0000 |
|
271 | 275 | files: foo |
|
272 | 276 | description: |
|
273 | 277 | addfoo |
|
274 | 278 | |
|
275 | 279 | |
|
276 | 280 | |
|
277 | 281 | --sourceorder should fail |
|
278 | 282 | |
|
279 | 283 | $ hg convert --sourcesort git-repo4 git-repo4-sourcesort-hg |
|
280 | 284 | initializing destination git-repo4-sourcesort-hg repository |
|
281 | 285 | abort: --sourcesort is not supported by this data source |
|
282 | 286 | [255] |
|
283 | 287 | |
|
284 | 288 | test sub modules |
|
285 | 289 | |
|
286 | 290 | $ mkdir git-repo5 |
|
287 | 291 | $ cd git-repo5 |
|
288 | 292 | $ git init-db >/dev/null 2>/dev/null |
|
289 | 293 | $ echo 'sub' >> foo |
|
290 | 294 | $ git add foo |
|
291 | 295 | $ commit -a -m 'addfoo' |
|
292 | 296 | $ BASE=`pwd` |
|
293 | 297 | $ cd .. |
|
294 | 298 | $ mkdir git-repo6 |
|
295 | 299 | $ cd git-repo6 |
|
296 | 300 | $ git init-db >/dev/null 2>/dev/null |
|
297 | 301 | $ git submodule add ${BASE} >/dev/null 2>/dev/null |
|
298 | 302 | $ commit -a -m 'addsubmodule' >/dev/null 2>/dev/null |
|
299 | 303 | $ cd .. |
|
300 | 304 | |
|
305 | test invalid splicemap1 | |
|
306 | ||
|
307 | $ cat > splicemap <<EOF | |
|
308 | > $VALIDID1 | |
|
309 | > EOF | |
|
310 | $ hg convert --splicemap splicemap git-repo2 git-repo2-splicemap1-hg | |
|
311 | initializing destination git-repo2-splicemap1-hg repository | |
|
312 | abort: syntax error in splicemap(1): child parent1[,parent2] expected | |
|
313 | [255] | |
|
314 | ||
|
315 | test invalid splicemap2 | |
|
316 | ||
|
317 | $ cat > splicemap <<EOF | |
|
318 | > $VALIDID1 $VALIDID2, $VALIDID2, $VALIDID2 | |
|
319 | > EOF | |
|
320 | $ hg convert --splicemap splicemap git-repo2 git-repo2-splicemap2-hg | |
|
321 | initializing destination git-repo2-splicemap2-hg repository | |
|
322 | abort: syntax error in splicemap(1): child parent1[,parent2] expected | |
|
323 | [255] | |
|
324 | ||
|
325 | test invalid splicemap3 | |
|
326 | ||
|
327 | $ cat > splicemap <<EOF | |
|
328 | > $INVALIDID1 $INVALIDID2 | |
|
329 | > EOF | |
|
330 | $ hg convert --splicemap splicemap git-repo2 git-repo2-splicemap3-hg | |
|
331 | initializing destination git-repo2-splicemap3-hg repository | |
|
332 | abort: splicemap entry afd12345af is not a valid revision identifier | |
|
333 | [255] | |
|
334 | ||
|
301 | 335 | convert sub modules |
|
302 | 336 | $ hg convert git-repo6 git-repo6-hg |
|
303 | 337 | initializing destination git-repo6-hg repository |
|
304 | 338 | scanning source... |
|
305 | 339 | sorting... |
|
306 | 340 | converting... |
|
307 | 341 | 0 addsubmodule |
|
308 | 342 | updating bookmarks |
|
309 | 343 | $ hg -R git-repo6-hg log -v |
|
310 | 344 | changeset: 0:* (glob) |
|
311 | 345 | bookmark: master |
|
312 | 346 | tag: tip |
|
313 | 347 | user: nottest <test@example.org> |
|
314 | 348 | date: Mon Jan 01 00:00:23 2007 +0000 |
|
315 | 349 | files: .hgsub .hgsubstate |
|
316 | 350 | description: |
|
317 | 351 | addsubmodule |
|
318 | 352 | |
|
319 | 353 | committer: test <test@example.org> |
|
320 | 354 | |
|
321 | 355 | |
|
322 | 356 | |
|
323 | 357 | $ cd git-repo6-hg |
|
324 | 358 | $ hg up >/dev/null 2>/dev/null |
|
325 | 359 | $ cat .hgsubstate |
|
326 | 360 | * git-repo5 (glob) |
|
327 | 361 | $ cd git-repo5 |
|
328 | 362 | $ cat foo |
|
329 | 363 | sub |
|
330 | 364 | |
|
331 | 365 | $ cd ../.. |
|
332 | 366 | |
|
333 | 367 | damaged git repository tests: |
|
334 | 368 | In case the hard-coded hashes change, the following commands can be used to |
|
335 | 369 | list the hashes and their corresponding types in the repository: |
|
336 | 370 | cd git-repo4/.git/objects |
|
337 | 371 | find . -type f | cut -c 3- | sed 's_/__' | xargs -n 1 -t git cat-file -t |
|
338 | 372 | cd ../../.. |
|
339 | 373 | |
|
340 | 374 | damage git repository by renaming a commit object |
|
341 | 375 | $ COMMIT_OBJ=1c/0ce3c5886f83a1d78a7b517cdff5cf9ca17bdd |
|
342 | 376 | $ mv git-repo4/.git/objects/$COMMIT_OBJ git-repo4/.git/objects/$COMMIT_OBJ.tmp |
|
343 | 377 | $ hg convert git-repo4 git-repo4-broken-hg 2>&1 | grep 'abort:' |
|
344 | 378 | abort: cannot read tags from git-repo4/.git |
|
345 | 379 | $ mv git-repo4/.git/objects/$COMMIT_OBJ.tmp git-repo4/.git/objects/$COMMIT_OBJ |
|
346 | 380 | damage git repository by renaming a blob object |
|
347 | 381 | |
|
348 | 382 | $ BLOB_OBJ=8b/137891791fe96927ad78e64b0aad7bded08bdc |
|
349 | 383 | $ mv git-repo4/.git/objects/$BLOB_OBJ git-repo4/.git/objects/$BLOB_OBJ.tmp |
|
350 | 384 | $ hg convert git-repo4 git-repo4-broken-hg 2>&1 | grep 'abort:' |
|
351 | 385 | abort: cannot read 'blob' object at 8b137891791fe96927ad78e64b0aad7bded08bdc |
|
352 | 386 | $ mv git-repo4/.git/objects/$BLOB_OBJ.tmp git-repo4/.git/objects/$BLOB_OBJ |
|
353 | 387 | damage git repository by renaming a tree object |
|
354 | 388 | |
|
355 | 389 | $ TREE_OBJ=72/49f083d2a63a41cc737764a86981eb5f3e4635 |
|
356 | 390 | $ mv git-repo4/.git/objects/$TREE_OBJ git-repo4/.git/objects/$TREE_OBJ.tmp |
|
357 | 391 | $ hg convert git-repo4 git-repo4-broken-hg 2>&1 | grep 'abort:' |
|
358 | 392 | abort: cannot read changes in 1c0ce3c5886f83a1d78a7b517cdff5cf9ca17bdd |
General Comments 0
You need to be logged in to leave comments.
Login now