28 def hgsub(self): |
28 def hgsub(self): |
29 return "%s = [git]%s" % (self.path, self.url) |
29 return "%s = [git]%s" % (self.path, self.url) |
30 |
30 |
31 def hgsubstate(self): |
31 def hgsubstate(self): |
32 return "%s %s" % (self.node, self.path) |
32 return "%s %s" % (self.node, self.path) |
|
33 |
|
34 # Keys in extra fields that should not be copied if the user requests. |
|
35 bannedextrakeys = set([ |
|
36 # Git commit object built-ins. |
|
37 'tree', |
|
38 'parent', |
|
39 'author', |
|
40 'committer', |
|
41 # Mercurial built-ins. |
|
42 'branch', |
|
43 'close', |
|
44 ]) |
33 |
45 |
34 class convert_git(common.converter_source, common.commandline): |
46 class convert_git(common.converter_source, common.commandline): |
35 # Windows does not support GIT_DIR= construct while other systems |
47 # Windows does not support GIT_DIR= construct while other systems |
36 # cannot remove environment variable. Just assume none have |
48 # cannot remove environment variable. Just assume none have |
37 # both issues. |
49 # both issues. |
89 |
101 |
90 self.path = path |
102 self.path = path |
91 self.submodules = [] |
103 self.submodules = [] |
92 |
104 |
93 self.catfilepipe = self.gitpipe('cat-file', '--batch') |
105 self.catfilepipe = self.gitpipe('cat-file', '--batch') |
|
106 |
|
107 self.copyextrakeys = self.ui.configlist('convert', 'git.extrakeys') |
|
108 banned = set(self.copyextrakeys) & bannedextrakeys |
|
109 if banned: |
|
110 raise error.Abort(_('copying of extra key is forbidden: %s') % |
|
111 _(', ').join(sorted(banned))) |
94 |
112 |
95 def after(self): |
113 def after(self): |
96 for f in self.catfilepipe: |
114 for f in self.catfilepipe: |
97 f.close() |
115 f.close() |
98 |
116 |
277 message = c[end + 2:] |
295 message = c[end + 2:] |
278 message = self.recode(message) |
296 message = self.recode(message) |
279 l = c[:end].splitlines() |
297 l = c[:end].splitlines() |
280 parents = [] |
298 parents = [] |
281 author = committer = None |
299 author = committer = None |
|
300 extra = {} |
282 for e in l[1:]: |
301 for e in l[1:]: |
283 n, v = e.split(" ", 1) |
302 n, v = e.split(" ", 1) |
284 if n == "author": |
303 if n == "author": |
285 p = v.split() |
304 p = v.split() |
286 tm, tz = p[-2:] |
305 tm, tz = p[-2:] |
293 committer = " ".join(p[:-2]) |
312 committer = " ".join(p[:-2]) |
294 if committer[0] == "<": committer = committer[1:-1] |
313 if committer[0] == "<": committer = committer[1:-1] |
295 committer = self.recode(committer) |
314 committer = self.recode(committer) |
296 if n == "parent": |
315 if n == "parent": |
297 parents.append(v) |
316 parents.append(v) |
|
317 if n in self.copyextrakeys: |
|
318 extra[n] = v |
298 |
319 |
299 if committer and committer != author: |
320 if committer and committer != author: |
300 message += "\ncommitter: %s\n" % committer |
321 message += "\ncommitter: %s\n" % committer |
301 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
322 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
302 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
323 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
303 date = tm + " " + str(tz) |
324 date = tm + " " + str(tz) |
304 |
325 |
305 c = common.commit(parents=parents, date=date, author=author, |
326 c = common.commit(parents=parents, date=date, author=author, |
306 desc=message, |
327 desc=message, |
307 rev=version) |
328 rev=version, |
|
329 extra=extra) |
308 return c |
330 return c |
309 |
331 |
310 def numcommits(self): |
332 def numcommits(self): |
311 output, ret = self.gitrunlines('rev-list', '--all') |
333 output, ret = self.gitrunlines('rev-list', '--all') |
312 if ret: |
334 if ret: |