Mercurial > hg
comparison hgext/convert/git.py @ 28365:cd599bc179fb
convert: git use absolute_import
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 02 Mar 2016 20:42:13 +0000 |
parents | aaa33ec3c951 |
children | ff0d3b6b287f |
comparison
equal
deleted
inserted
replaced
28364:f1460af18c50 | 28365:cd599bc179fb |
---|---|
2 # | 2 # |
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others | 3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 from __future__ import absolute_import | |
7 | 8 |
8 import os | 9 import os |
9 import subprocess | 10 import subprocess |
10 from mercurial import util, config, error | 11 from mercurial import ( |
11 from mercurial.node import hex, nullid | 12 config, |
13 error, | |
14 node as nodemod, | |
15 util, | |
16 ) | |
12 from mercurial.i18n import _ | 17 from mercurial.i18n import _ |
13 | 18 |
14 from common import NoRepo, commit, converter_source, checktool | 19 from . import ( |
20 common, | |
21 ) | |
15 | 22 |
16 class submodule(object): | 23 class submodule(object): |
17 def __init__(self, path, node, url): | 24 def __init__(self, path, node, url): |
18 self.path = path | 25 self.path = path |
19 self.node = node | 26 self.node = node |
23 return "%s = [git]%s" % (self.path, self.url) | 30 return "%s = [git]%s" % (self.path, self.url) |
24 | 31 |
25 def hgsubstate(self): | 32 def hgsubstate(self): |
26 return "%s %s" % (self.node, self.path) | 33 return "%s %s" % (self.node, self.path) |
27 | 34 |
28 class convert_git(converter_source): | 35 class convert_git(common.converter_source): |
29 # Windows does not support GIT_DIR= construct while other systems | 36 # Windows does not support GIT_DIR= construct while other systems |
30 # cannot remove environment variable. Just assume none have | 37 # cannot remove environment variable. Just assume none have |
31 # both issues. | 38 # both issues. |
32 if util.safehasattr(os, 'unsetenv'): | 39 if util.safehasattr(os, 'unsetenv'): |
33 def gitopen(self, s, err=None): | 40 def gitopen(self, s, err=None): |
90 super(convert_git, self).__init__(ui, path, revs=revs) | 97 super(convert_git, self).__init__(ui, path, revs=revs) |
91 | 98 |
92 if os.path.isdir(path + "/.git"): | 99 if os.path.isdir(path + "/.git"): |
93 path += "/.git" | 100 path += "/.git" |
94 if not os.path.exists(path + "/objects"): | 101 if not os.path.exists(path + "/objects"): |
95 raise NoRepo(_("%s does not look like a Git repository") % path) | 102 raise common.NoRepo(_("%s does not look like a Git repository") % |
103 path) | |
96 | 104 |
97 # The default value (50) is based on the default for 'git diff'. | 105 # The default value (50) is based on the default for 'git diff'. |
98 similarity = ui.configint('convert', 'git.similarity', default=50) | 106 similarity = ui.configint('convert', 'git.similarity', default=50) |
99 if similarity < 0 or similarity > 100: | 107 if similarity < 0 or similarity > 100: |
100 raise error.Abort(_('similarity must be between 0 and 100')) | 108 raise error.Abort(_('similarity must be between 0 and 100')) |
105 if findcopiesharder: | 113 if findcopiesharder: |
106 self.simopt += ' --find-copies-harder' | 114 self.simopt += ' --find-copies-harder' |
107 else: | 115 else: |
108 self.simopt = '' | 116 self.simopt = '' |
109 | 117 |
110 checktool('git', 'git') | 118 common.checktool('git', 'git') |
111 | 119 |
112 self.path = path | 120 self.path = path |
113 self.submodules = [] | 121 self.submodules = [] |
114 | 122 |
115 self.catfilepipe = self.gitpipe('git cat-file --batch') | 123 self.catfilepipe = self.gitpipe('git cat-file --batch') |
132 if ret: | 140 if ret: |
133 raise error.Abort(_('cannot retrieve git head "%s"') % rev) | 141 raise error.Abort(_('cannot retrieve git head "%s"') % rev) |
134 return heads | 142 return heads |
135 | 143 |
136 def catfile(self, rev, type): | 144 def catfile(self, rev, type): |
137 if rev == hex(nullid): | 145 if rev == nodemod.nullhex: |
138 raise IOError | 146 raise IOError |
139 self.catfilepipe[0].write(rev+'\n') | 147 self.catfilepipe[0].write(rev+'\n') |
140 self.catfilepipe[0].flush() | 148 self.catfilepipe[0].flush() |
141 info = self.catfilepipe[1].readline().split() | 149 info = self.catfilepipe[1].readline().split() |
142 if info[1] != type: | 150 if info[1] != type: |
149 # read the trailing newline | 157 # read the trailing newline |
150 self.catfilepipe[1].read(1) | 158 self.catfilepipe[1].read(1) |
151 return data | 159 return data |
152 | 160 |
153 def getfile(self, name, rev): | 161 def getfile(self, name, rev): |
154 if rev == hex(nullid): | 162 if rev == nodemod.nullhex: |
155 return None, None | 163 return None, None |
156 if name == '.hgsub': | 164 if name == '.hgsub': |
157 data = '\n'.join([m.hgsub() for m in self.submoditer()]) | 165 data = '\n'.join([m.hgsub() for m in self.submoditer()]) |
158 mode = '' | 166 mode = '' |
159 elif name == '.hgsubstate': | 167 elif name == '.hgsubstate': |
163 data = self.catfile(rev, "blob") | 171 data = self.catfile(rev, "blob") |
164 mode = self.modecache[(name, rev)] | 172 mode = self.modecache[(name, rev)] |
165 return data, mode | 173 return data, mode |
166 | 174 |
167 def submoditer(self): | 175 def submoditer(self): |
168 null = hex(nullid) | 176 null = nodemod.nullhex |
169 for m in sorted(self.submodules, key=lambda p: p.path): | 177 for m in sorted(self.submodules, key=lambda p: p.path): |
170 if m.node != null: | 178 if m.node != null: |
171 yield m | 179 yield m |
172 | 180 |
173 def parsegitmodules(self, content): | 181 def parsegitmodules(self, content): |
238 return | 246 return |
239 | 247 |
240 subexists[0] = True | 248 subexists[0] = True |
241 if entry[4] == 'D' or renamesource: | 249 if entry[4] == 'D' or renamesource: |
242 subdeleted[0] = True | 250 subdeleted[0] = True |
243 changes.append(('.hgsub', hex(nullid))) | 251 changes.append(('.hgsub', nodemod.nullhex)) |
244 else: | 252 else: |
245 changes.append(('.hgsub', '')) | 253 changes.append(('.hgsub', '')) |
246 elif entry[1] == '160000' or entry[0] == ':160000': | 254 elif entry[1] == '160000' or entry[0] == ':160000': |
247 if not skipsubmodules: | 255 if not skipsubmodules: |
248 subexists[0] = True | 256 subexists[0] = True |
249 else: | 257 else: |
250 if renamesource: | 258 if renamesource: |
251 h = hex(nullid) | 259 h = nodemod.nullhex |
252 self.modecache[(f, h)] = (p and "x") or (s and "l") or "" | 260 self.modecache[(f, h)] = (p and "x") or (s and "l") or "" |
253 changes.append((f, h)) | 261 changes.append((f, h)) |
254 | 262 |
255 while i < lcount: | 263 while i < lcount: |
256 l = difftree[i] | 264 l = difftree[i] |
285 if fh.close(): | 293 if fh.close(): |
286 raise error.Abort(_('cannot read changes in %s') % version) | 294 raise error.Abort(_('cannot read changes in %s') % version) |
287 | 295 |
288 if subexists[0]: | 296 if subexists[0]: |
289 if subdeleted[0]: | 297 if subdeleted[0]: |
290 changes.append(('.hgsubstate', hex(nullid))) | 298 changes.append(('.hgsubstate', nodemod.nullhex)) |
291 else: | 299 else: |
292 self.retrievegitmodules(version) | 300 self.retrievegitmodules(version) |
293 changes.append(('.hgsubstate', '')) | 301 changes.append(('.hgsubstate', '')) |
294 return (changes, copies, set()) | 302 return (changes, copies, set()) |
295 | 303 |
322 message += "\ncommitter: %s\n" % committer | 330 message += "\ncommitter: %s\n" % committer |
323 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] | 331 tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] |
324 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) | 332 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
325 date = tm + " " + str(tz) | 333 date = tm + " " + str(tz) |
326 | 334 |
327 c = commit(parents=parents, date=date, author=author, desc=message, | 335 c = common.commit(parents=parents, date=date, author=author, |
328 rev=version) | 336 desc=message, |
337 rev=version) | |
329 return c | 338 return c |
330 | 339 |
331 def numcommits(self): | 340 def numcommits(self): |
332 return len([None for _ in self.gitopen('git rev-list --all')]) | 341 return len([None for _ in self.gitopen('git rev-list --all')]) |
333 | 342 |