Mercurial > hg
comparison hgext/convert/gnuarch.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 058c2468b2f5 |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
24 dateutil, | 24 dateutil, |
25 procutil, | 25 procutil, |
26 ) | 26 ) |
27 from . import common | 27 from . import common |
28 | 28 |
29 | |
29 class gnuarch_source(common.converter_source, common.commandline): | 30 class gnuarch_source(common.converter_source, common.commandline): |
30 | |
31 class gnuarch_rev(object): | 31 class gnuarch_rev(object): |
32 def __init__(self, rev): | 32 def __init__(self, rev): |
33 self.rev = rev | 33 self.rev = rev |
34 self.summary = '' | 34 self.summary = '' |
35 self.date = None | 35 self.date = None |
43 | 43 |
44 def __init__(self, ui, repotype, path, revs=None): | 44 def __init__(self, ui, repotype, path, revs=None): |
45 super(gnuarch_source, self).__init__(ui, repotype, path, revs=revs) | 45 super(gnuarch_source, self).__init__(ui, repotype, path, revs=revs) |
46 | 46 |
47 if not os.path.exists(os.path.join(path, '{arch}')): | 47 if not os.path.exists(os.path.join(path, '{arch}')): |
48 raise common.NoRepo(_("%s does not look like a GNU Arch repository") | 48 raise common.NoRepo( |
49 % path) | 49 _("%s does not look like a GNU Arch repository") % path |
50 ) | |
50 | 51 |
51 # Could use checktool, but we want to check for baz or tla. | 52 # Could use checktool, but we want to check for baz or tla. |
52 self.execmd = None | 53 self.execmd = None |
53 if procutil.findexe('baz'): | 54 if procutil.findexe('baz'): |
54 self.execmd = 'baz' | 55 self.execmd = 'baz' |
72 self.encoding = encoding.encoding | 73 self.encoding = encoding.encoding |
73 self.archives = [] | 74 self.archives = [] |
74 | 75 |
75 def before(self): | 76 def before(self): |
76 # Get registered archives | 77 # Get registered archives |
77 self.archives = [i.rstrip('\n') | 78 self.archives = [ |
78 for i in self.runlines0('archives', '-n')] | 79 i.rstrip('\n') for i in self.runlines0('archives', '-n') |
80 ] | |
79 | 81 |
80 if self.execmd == 'tla': | 82 if self.execmd == 'tla': |
81 output = self.run0('tree-version', self.path) | 83 output = self.run0('tree-version', self.path) |
82 else: | 84 else: |
83 output = self.run0('tree-version', '-d', self.path) | 85 output = self.run0('tree-version', '-d', self.path) |
84 self.treeversion = output.strip() | 86 self.treeversion = output.strip() |
85 | 87 |
86 # Get name of temporary directory | 88 # Get name of temporary directory |
87 version = self.treeversion.split('/') | 89 version = self.treeversion.split('/') |
88 self.tmppath = os.path.join(pycompat.fsencode(tempfile.gettempdir()), | 90 self.tmppath = os.path.join( |
89 'hg-%s' % version[1]) | 91 pycompat.fsencode(tempfile.gettempdir()), 'hg-%s' % version[1] |
92 ) | |
90 | 93 |
91 # Generate parents dictionary | 94 # Generate parents dictionary |
92 self.parents[None] = [] | 95 self.parents[None] = [] |
93 treeversion = self.treeversion | 96 treeversion = self.treeversion |
94 child = None | 97 child = None |
95 while treeversion: | 98 while treeversion: |
96 self.ui.status(_('analyzing tree version %s...\n') % treeversion) | 99 self.ui.status(_('analyzing tree version %s...\n') % treeversion) |
97 | 100 |
98 archive = treeversion.split('/')[0] | 101 archive = treeversion.split('/')[0] |
99 if archive not in self.archives: | 102 if archive not in self.archives: |
100 self.ui.status(_('tree analysis stopped because it points to ' | 103 self.ui.status( |
101 'an unregistered archive %s...\n') % archive) | 104 _( |
105 'tree analysis stopped because it points to ' | |
106 'an unregistered archive %s...\n' | |
107 ) | |
108 % archive | |
109 ) | |
102 break | 110 break |
103 | 111 |
104 # Get the complete list of revisions for that tree version | 112 # Get the complete list of revisions for that tree version |
105 output, status = self.runlines('revisions', '-r', '-f', treeversion) | 113 output, status = self.runlines('revisions', '-r', '-f', treeversion) |
106 self.checkexit(status, 'failed retrieving revisions for %s' | 114 self.checkexit( |
107 % treeversion) | 115 status, 'failed retrieving revisions for %s' % treeversion |
116 ) | |
108 | 117 |
109 # No new iteration unless a revision has a continuation-of header | 118 # No new iteration unless a revision has a continuation-of header |
110 treeversion = None | 119 treeversion = None |
111 | 120 |
112 for l in output: | 121 for l in output: |
115 self.parents[rev] = [] | 124 self.parents[rev] = [] |
116 | 125 |
117 # Read author, date and summary | 126 # Read author, date and summary |
118 catlog, status = self.run('cat-log', '-d', self.path, rev) | 127 catlog, status = self.run('cat-log', '-d', self.path, rev) |
119 if status: | 128 if status: |
120 catlog = self.run0('cat-archive-log', rev) | 129 catlog = self.run0('cat-archive-log', rev) |
121 self._parsecatlog(catlog, rev) | 130 self._parsecatlog(catlog, rev) |
122 | 131 |
123 # Populate the parents map | 132 # Populate the parents map |
124 self.parents[child].append(rev) | 133 self.parents[child].append(rev) |
125 | 134 |
130 # Check if we have to follow the usual incremental history | 139 # Check if we have to follow the usual incremental history |
131 # or if we have to 'jump' to a different treeversion given | 140 # or if we have to 'jump' to a different treeversion given |
132 # by the continuation-of header. | 141 # by the continuation-of header. |
133 if self.changes[rev].continuationof: | 142 if self.changes[rev].continuationof: |
134 treeversion = '--'.join( | 143 treeversion = '--'.join( |
135 self.changes[rev].continuationof.split('--')[:-1]) | 144 self.changes[rev].continuationof.split('--')[:-1] |
145 ) | |
136 break | 146 break |
137 | 147 |
138 # If we reached a base-0 revision w/o any continuation-of | 148 # If we reached a base-0 revision w/o any continuation-of |
139 # header, it means the tree history ends here. | 149 # header, it means the tree history ends here. |
140 if rev[-6:] == 'base-0': | 150 if rev[-6:] == 'base-0': |
187 self.lastrev = rev | 197 self.lastrev = rev |
188 return sorted(set(changes)), copies, set() | 198 return sorted(set(changes)), copies, set() |
189 | 199 |
190 def getcommit(self, rev): | 200 def getcommit(self, rev): |
191 changes = self.changes[rev] | 201 changes = self.changes[rev] |
192 return common.commit(author=changes.author, date=changes.date, | 202 return common.commit( |
193 desc=changes.summary, parents=self.parents[rev], | 203 author=changes.author, |
194 rev=rev) | 204 date=changes.date, |
205 desc=changes.summary, | |
206 parents=self.parents[rev], | |
207 rev=rev, | |
208 ) | |
195 | 209 |
196 def gettags(self): | 210 def gettags(self): |
197 return self.tags | 211 return self.tags |
198 | 212 |
199 def _execute(self, cmd, *args, **kwargs): | 213 def _execute(self, cmd, *args, **kwargs): |
205 self.ui.debug(cmdline, '\n') | 219 self.ui.debug(cmdline, '\n') |
206 return os.system(pycompat.rapply(procutil.tonativestr, cmdline)) | 220 return os.system(pycompat.rapply(procutil.tonativestr, cmdline)) |
207 | 221 |
208 def _update(self, rev): | 222 def _update(self, rev): |
209 self.ui.debug('applying revision %s...\n' % rev) | 223 self.ui.debug('applying revision %s...\n' % rev) |
210 changeset, status = self.runlines('replay', '-d', self.tmppath, | 224 changeset, status = self.runlines('replay', '-d', self.tmppath, rev) |
211 rev) | |
212 if status: | 225 if status: |
213 # Something went wrong while merging (baz or tla | 226 # Something went wrong while merging (baz or tla |
214 # issue?), get latest revision and try from there | 227 # issue?), get latest revision and try from there |
215 shutil.rmtree(self.tmppath, ignore_errors=True) | 228 shutil.rmtree(self.tmppath, ignore_errors=True) |
216 self._obtainrevision(rev) | 229 self._obtainrevision(rev) |
217 else: | 230 else: |
218 old_rev = self.parents[rev][0] | 231 old_rev = self.parents[rev][0] |
219 self.ui.debug('computing changeset between %s and %s...\n' | 232 self.ui.debug( |
220 % (old_rev, rev)) | 233 'computing changeset between %s and %s...\n' % (old_rev, rev) |
234 ) | |
221 self._parsechangeset(changeset, rev) | 235 self._parsechangeset(changeset, rev) |
222 | 236 |
223 def _getfile(self, name, rev): | 237 def _getfile(self, name, rev): |
224 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode | 238 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode |
225 if stat.S_ISLNK(mode): | 239 if stat.S_ISLNK(mode): |
284 try: | 298 try: |
285 catlog = self.catlogparser.parsestr(data) | 299 catlog = self.catlogparser.parsestr(data) |
286 | 300 |
287 # Commit date | 301 # Commit date |
288 self.changes[rev].date = dateutil.datestr( | 302 self.changes[rev].date = dateutil.datestr( |
289 dateutil.strdate(catlog['Standard-date'], | 303 dateutil.strdate(catlog['Standard-date'], '%Y-%m-%d %H:%M:%S') |
290 '%Y-%m-%d %H:%M:%S')) | 304 ) |
291 | 305 |
292 # Commit author | 306 # Commit author |
293 self.changes[rev].author = self.recode(catlog['Creator']) | 307 self.changes[rev].author = self.recode(catlog['Creator']) |
294 | 308 |
295 # Commit description | 309 # Commit description |
296 self.changes[rev].summary = '\n\n'.join((catlog['Summary'], | 310 self.changes[rev].summary = '\n\n'.join( |
297 catlog.get_payload())) | 311 (catlog['Summary'], catlog.get_payload()) |
312 ) | |
298 self.changes[rev].summary = self.recode(self.changes[rev].summary) | 313 self.changes[rev].summary = self.recode(self.changes[rev].summary) |
299 | 314 |
300 # Commit revision origin when dealing with a branch or tag | 315 # Commit revision origin when dealing with a branch or tag |
301 if 'Continuation-of' in catlog: | 316 if 'Continuation-of' in catlog: |
302 self.changes[rev].continuationof = self.recode( | 317 self.changes[rev].continuationof = self.recode( |
303 catlog['Continuation-of']) | 318 catlog['Continuation-of'] |
319 ) | |
304 except Exception: | 320 except Exception: |
305 raise error.Abort(_('could not parse cat-log of %s') % rev) | 321 raise error.Abort(_('could not parse cat-log of %s') % rev) |
306 | 322 |
307 def _parsechangeset(self, data, rev): | 323 def _parsechangeset(self, data, rev): |
308 for l in data: | 324 for l in data: |