Mercurial > hg
diff hgext/convert/subversion.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 | c004340dc687 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/convert/subversion.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/convert/subversion.py Sun Oct 06 09:45:02 2019 -0400 @@ -52,17 +52,20 @@ import svn.delta from . import transport import warnings - warnings.filterwarnings('ignore', - module='svn.core', - category=DeprecationWarning) - svn.core.SubversionException # trigger import to catch error + + warnings.filterwarnings( + 'ignore', module='svn.core', category=DeprecationWarning + ) + svn.core.SubversionException # trigger import to catch error except ImportError: svn = None + class SvnPathNotFound(Exception): pass + def revsplit(rev): """Parse a revision string and return (uuid, path, revnum). >>> revsplit(b'svn:a2147622-4a9f-4db4-a8d3-13562ff547b2' @@ -89,6 +92,7 @@ mod = '/' + parts[1] return uuid, mod, revnum + def quote(s): # As of svn 1.7, many svn calls expect "canonical" paths. In # theory, we should call svn.core.*canonicalize() on all paths @@ -99,6 +103,7 @@ # libsvn_subr/path.c. return urlreq.quote(s, "!$&'()*+,-./:=@_~") + def geturl(path): try: return svn.client.url_from_path(svn.core.svn_path_canonicalize(path)) @@ -115,37 +120,54 @@ path = 'file://%s' % quote(path) return svn.core.svn_path_canonicalize(path) + def optrev(number): optrev = svn.core.svn_opt_revision_t() optrev.kind = svn.core.svn_opt_revision_number optrev.value.number = number return optrev + class changedpath(object): def __init__(self, p): self.copyfrom_path = p.copyfrom_path self.copyfrom_rev = p.copyfrom_rev self.action = p.action -def get_log_child(fp, url, paths, start, end, limit=0, - discover_changed_paths=True, strict_node_history=False): + +def get_log_child( + fp, + url, + paths, + start, + end, + limit=0, + discover_changed_paths=True, + strict_node_history=False, +): protocol = -1 + def receiver(orig_paths, revnum, author, date, message, pool): paths = {} if orig_paths is not None: for k, v in orig_paths.iteritems(): paths[k] = changedpath(v) - pickle.dump((paths, revnum, author, date, message), - fp, protocol) + pickle.dump((paths, revnum, author, date, message), fp, protocol) try: # Use an ra of our own so that our parent can consume # our results without confusing the server. t = transport.SvnRaTransport(url=url) - svn.ra.get_log(t.ra, paths, start, end, limit, - discover_changed_paths, - strict_node_history, - receiver) + svn.ra.get_log( + t.ra, + paths, + start, + end, + limit, + discover_changed_paths, + strict_node_history, + receiver, + ) except IOError: # Caller may interrupt the iteration pickle.dump(None, fp, protocol) @@ -159,19 +181,23 @@ # there is no need for clean termination. os._exit(0) + def debugsvnlog(ui, **opts): """Fetch SVN log in a subprocess and channel them back to parent to avoid memory collection issues. """ if svn is None: - raise error.Abort(_('debugsvnlog could not load Subversion python ' - 'bindings')) + raise error.Abort( + _('debugsvnlog could not load Subversion python ' 'bindings') + ) args = decodeargs(ui.fin.read()) get_log_child(ui.fout, *args) + class logstream(object): """Interruptible revision log iterator.""" + def __init__(self, stdout): self._stdout = stdout @@ -180,8 +206,12 @@ try: entry = pickle.load(self._stdout) except EOFError: - raise error.Abort(_('Mercurial failed to run itself, check' - ' hg executable is in PATH')) + raise error.Abort( + _( + 'Mercurial failed to run itself, check' + ' hg executable is in PATH' + ) + ) try: orig_paths, revnum, author, date, message = entry except (TypeError, ValueError): @@ -195,13 +225,22 @@ self._stdout.close() self._stdout = None + class directlogstream(list): """Direct revision log iterator. This can be used for debugging and development but it will probably leak memory and is not suitable for real conversions.""" - def __init__(self, url, paths, start, end, limit=0, - discover_changed_paths=True, strict_node_history=False): + def __init__( + self, + url, + paths, + start, + end, + limit=0, + discover_changed_paths=True, + strict_node_history=False, + ): def receiver(orig_paths, revnum, author, date, message, pool): paths = {} if orig_paths is not None: @@ -212,14 +251,21 @@ # Use an ra of our own so that our parent can consume # our results without confusing the server. t = transport.SvnRaTransport(url=url) - svn.ra.get_log(t.ra, paths, start, end, limit, - discover_changed_paths, - strict_node_history, - receiver) + svn.ra.get_log( + t.ra, + paths, + start, + end, + limit, + discover_changed_paths, + strict_node_history, + receiver, + ) def close(self): pass + # Check to see if the given path is a local Subversion repo. Verify this by # looking for several svn-specific files and directories in the given # directory. @@ -229,6 +275,7 @@ return False return True + # Check to see if a given path is the root of an svn repo over http. We verify # this by requesting a version-controlled URL we know can't exist and looking # for the svn-specific "not found" XML. @@ -240,9 +287,13 @@ except urlerr.httperror as inst: if inst.code != 404: # Except for 404 we cannot know for sure this is not an svn repo - ui.warn(_('svn: cannot probe remote repository, assume it could ' - 'be a subversion repository. Use --source-type if you ' - 'know better.\n')) + ui.warn( + _( + 'svn: cannot probe remote repository, assume it could ' + 'be a subversion repository. Use --source-type if you ' + 'know better.\n' + ) + ) return True data = inst.fp.read() except Exception: @@ -250,16 +301,24 @@ return False return '<m:human-readable errcode="160013">' in data -protomap = {'http': httpcheck, - 'https': httpcheck, - 'file': filecheck, - } + +protomap = { + 'http': httpcheck, + 'https': httpcheck, + 'file': filecheck, +} + + def issvnurl(ui, url): try: proto, path = url.split('://', 1) if proto == 'file': - if (pycompat.iswindows and path[:1] == '/' - and path[1:2].isalpha() and path[2:6].lower() == '%3a/'): + if ( + pycompat.iswindows + and path[:1] == '/' + and path[1:2].isalpha() + and path[2:6].lower() == '%3a/' + ): path = path[:2] + ':/' + path[6:] path = urlreq.url2pathname(path) except ValueError: @@ -274,6 +333,7 @@ path = path.rsplit('/', 1)[0] return False + # SVN conversion code stolen from bzr-svn and tailor # # Subversion looks like a versioned filesystem, branches structures @@ -292,23 +352,38 @@ def __init__(self, ui, repotype, url, revs=None): super(svn_source, self).__init__(ui, repotype, url, revs=revs) - if not (url.startswith('svn://') or url.startswith('svn+ssh://') or - (os.path.exists(url) and - os.path.exists(os.path.join(url, '.svn'))) or - issvnurl(ui, url)): - raise NoRepo(_("%s does not look like a Subversion repository") - % url) + if not ( + url.startswith('svn://') + or url.startswith('svn+ssh://') + or ( + os.path.exists(url) + and os.path.exists(os.path.join(url, '.svn')) + ) + or issvnurl(ui, url) + ): + raise NoRepo( + _("%s does not look like a Subversion repository") % url + ) if svn is None: raise MissingTool(_('could not load Subversion python bindings')) try: version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR if version < (1, 4): - raise MissingTool(_('Subversion python bindings %d.%d found, ' - '1.4 or later required') % version) + raise MissingTool( + _( + 'Subversion python bindings %d.%d found, ' + '1.4 or later required' + ) + % version + ) except AttributeError: - raise MissingTool(_('Subversion python bindings are too old, 1.4 ' - 'or later required')) + raise MissingTool( + _( + 'Subversion python bindings are too old, 1.4 ' + 'or later required' + ) + ) self.lastrevs = {} @@ -318,12 +393,12 @@ # deleted branches. at = url.rfind('@') if at >= 0: - latest = int(url[at + 1:]) + latest = int(url[at + 1 :]) url = url[:at] except ValueError: pass self.url = geturl(url) - self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 + self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 try: self.transport = transport.SvnRaTransport(url=self.url) self.ra = self.transport.ra @@ -331,7 +406,7 @@ self.baseurl = svn.ra.get_repos_root(self.ra) # Module is either empty or a repository path starting with # a slash and not ending with a slash. - self.module = urlreq.unquote(self.url[len(self.baseurl):]) + self.module = urlreq.unquote(self.url[len(self.baseurl) :]) self.prevmodule = None self.rootmodule = self.module self.commits = {} @@ -339,22 +414,33 @@ self.uuid = svn.ra.get_uuid(self.ra) except svn.core.SubversionException: ui.traceback() - svnversion = '%d.%d.%d' % (svn.core.SVN_VER_MAJOR, - svn.core.SVN_VER_MINOR, - svn.core.SVN_VER_MICRO) - raise NoRepo(_("%s does not look like a Subversion repository " - "to libsvn version %s") - % (self.url, svnversion)) + svnversion = '%d.%d.%d' % ( + svn.core.SVN_VER_MAJOR, + svn.core.SVN_VER_MINOR, + svn.core.SVN_VER_MICRO, + ) + raise NoRepo( + _( + "%s does not look like a Subversion repository " + "to libsvn version %s" + ) + % (self.url, svnversion) + ) if revs: if len(revs) > 1: - raise error.Abort(_('subversion source does not support ' - 'specifying multiple revisions')) + raise error.Abort( + _( + 'subversion source does not support ' + 'specifying multiple revisions' + ) + ) try: latest = int(revs[0]) except ValueError: - raise error.Abort(_('svn: revision %s is not an integer') % - revs[0]) + raise error.Abort( + _('svn: revision %s is not an integer') % revs[0] + ) trunkcfg = self.ui.config('convert', 'svn.trunk') if trunkcfg is None: @@ -366,16 +452,16 @@ if self.startrev < 0: self.startrev = 0 except ValueError: - raise error.Abort(_('svn: start revision %s is not an integer') - % self.startrev) + raise error.Abort( + _('svn: start revision %s is not an integer') % self.startrev + ) try: self.head = self.latest(self.module, latest) except SvnPathNotFound: self.head = None if not self.head: - raise error.Abort(_('no revision found in module %s') - % self.module) + raise error.Abort(_('no revision found in module %s') % self.module) self.last_changed = self.revnum(self.head) self._changescache = (None, None) @@ -397,14 +483,17 @@ def exists(self, path, optrev): try: - svn.client.ls(self.url.rstrip('/') + '/' + quote(path), - optrev, False, self.ctx) + svn.client.ls( + self.url.rstrip('/') + '/' + quote(path), + optrev, + False, + self.ctx, + ) return True except svn.core.SubversionException: return False def getheads(self): - def isdir(path, revnum): kind = self._checkpath(path, revnum) return kind == svn.core.svn_node_dir @@ -419,8 +508,10 @@ # we are converting from inside this directory return None if cfgpath: - raise error.Abort(_('expected %s to be at %r, but not found' - ) % (name, path)) + raise error.Abort( + _('expected %s to be at %r, but not found') + % (name, path) + ) return None self.ui.note(_('found %s at %r\n') % (name, path)) return path @@ -438,19 +529,21 @@ self.module += '/' + trunk self.head = self.latest(self.module, self.last_changed) if not self.head: - raise error.Abort(_('no revision found in module %s') - % self.module) + raise error.Abort( + _('no revision found in module %s') % self.module + ) # First head in the list is the module's head self.heads = [self.head] if self.tags is not None: - self.tags = '%s/%s' % (oldmodule , (self.tags or 'tags')) + self.tags = '%s/%s' % (oldmodule, (self.tags or 'tags')) # Check if branches bring a few more heads to the list if branches: rpath = self.url.strip('/') - branchnames = svn.client.ls(rpath + '/' + quote(branches), - rev, False, self.ctx) + branchnames = svn.client.ls( + rpath + '/' + quote(branches), rev, False, self.ctx + ) for branch in sorted(branchnames): module = '%s/%s/%s' % (oldmodule, branches, branch) if not isdir(module, self.last_changed): @@ -459,19 +552,25 @@ if not brevid: self.ui.note(_('ignoring empty branch %s\n') % branch) continue - self.ui.note(_('found branch %s at %d\n') % - (branch, self.revnum(brevid))) + self.ui.note( + _('found branch %s at %d\n') % (branch, self.revnum(brevid)) + ) self.heads.append(brevid) if self.startrev and self.heads: if len(self.heads) > 1: - raise error.Abort(_('svn: start revision is not supported ' - 'with more than one branch')) + raise error.Abort( + _( + 'svn: start revision is not supported ' + 'with more than one branch' + ) + ) revnum = self.revnum(self.heads[0]) if revnum < self.startrev: raise error.Abort( _('svn: no revision found after start revision %d') - % self.startrev) + % self.startrev + ) return self.heads @@ -483,10 +582,14 @@ if full or not parents: # Perform a full checkout on roots uuid, module, revnum = revsplit(rev) - entries = svn.client.ls(self.baseurl + quote(module), - optrev(revnum), True, self.ctx) - files = [n for n, e in entries.iteritems() - if e.kind == svn.core.svn_node_file] + entries = svn.client.ls( + self.baseurl + quote(module), optrev(revnum), True, self.ctx + ) + files = [ + n + for n, e in entries.iteritems() + if e.kind == svn.core.svn_node_file + ] self.removed = set() files.sort() @@ -533,11 +636,16 @@ def checkrevformat(self, revstr, mapname='splicemap'): """ fails if revision format does not match the correct format""" - if not re.match(r'svn:[0-9a-f]{8,8}-[0-9a-f]{4,4}-' - r'[0-9a-f]{4,4}-[0-9a-f]{4,4}-[0-9a-f]' - r'{12,12}(.*)\@[0-9]+$',revstr): - raise error.Abort(_('%s entry %s is not a valid revision' - ' identifier') % (mapname, revstr)) + if not re.match( + r'svn:[0-9a-f]{8,8}-[0-9a-f]{4,4}-' + r'[0-9a-f]{4,4}-[0-9a-f]{4,4}-[0-9a-f]' + r'{12,12}(.*)\@[0-9]+$', + revstr, + ): + raise error.Abort( + _('%s entry %s is not a valid revision' ' identifier') + % (mapname, revstr) + ) def numcommits(self): return int(self.head.rsplit('@', 1)[1]) - self.startrev @@ -567,8 +675,11 @@ origpaths, revnum, author, date, message = entry if not origpaths: origpaths = [] - copies = [(e.copyfrom_path, e.copyfrom_rev, p) for p, e - in origpaths.iteritems() if e.copyfrom_path] + copies = [ + (e.copyfrom_path, e.copyfrom_rev, p) + for p, e in origpaths.iteritems() + if e.copyfrom_path + ] # Apply moves/copies from more specific to general copies.sort(reverse=True) @@ -582,7 +693,7 @@ continue for tag in pendings: if tag[0].startswith(dest): - tagpath = source + tag[0][len(dest):] + tagpath = source + tag[0][len(dest) :] tag[:2] = [tagpath, sourcerev] break else: @@ -595,21 +706,28 @@ # Here/tags/tag.1 discarded as well as its children. # It happens with tools like cvs2svn. Such tags cannot # be represented in mercurial. - addeds = dict((p, e.copyfrom_path) for p, e - in origpaths.iteritems() - if e.action == 'A' and e.copyfrom_path) + addeds = dict( + (p, e.copyfrom_path) + for p, e in origpaths.iteritems() + if e.action == 'A' and e.copyfrom_path + ) badroots = set() for destroot in addeds: for source, sourcerev, dest in pendings: - if (not dest.startswith(destroot + '/') - or source.startswith(addeds[destroot] + '/')): + if not dest.startswith( + destroot + '/' + ) or source.startswith(addeds[destroot] + '/'): continue badroots.add(destroot) break for badroot in badroots: - pendings = [p for p in pendings if p[2] != badroot - and not p[2].startswith(badroot + '/')] + pendings = [ + p + for p in pendings + if p[2] != badroot + and not p[2].startswith(badroot + '/') + ] # Tell tag renamings from tag creations renamings = [] @@ -642,10 +760,12 @@ if not self.wc: return if self.convertfp is None: - self.convertfp = open(os.path.join(self.wc, '.svn', 'hg-shamap'), - 'ab') - self.convertfp.write(util.tonativeeol('%s %d\n' - % (destrev, self.revnum(rev)))) + self.convertfp = open( + os.path.join(self.wc, '.svn', 'hg-shamap'), 'ab' + ) + self.convertfp.write( + util.tonativeeol('%s %d\n' % (destrev, self.revnum(rev))) + ) self.convertfp.flush() def revid(self, revnum, module=None): @@ -662,6 +782,7 @@ reported. Return None if computed module does not belong to rootmodule subtree. """ + def findchanges(path, start, stop=None): stream = self._getlog([path], start, stop or 1) try: @@ -675,12 +796,13 @@ break for p in paths: - if (not path.startswith(p) or - not paths[p].copyfrom_path): + if not path.startswith(p) or not paths[p].copyfrom_path: continue - newpath = paths[p].copyfrom_path + path[len(p):] - self.ui.debug("branch renamed from %s to %s at %d\n" % - (path, newpath, revnum)) + newpath = paths[p].copyfrom_path + path[len(p) :] + self.ui.debug( + "branch renamed from %s to %s at %d\n" + % (path, newpath, revnum) + ) path = newpath break if not paths: @@ -703,8 +825,9 @@ except svn.core.SubversionException: dirent = None if not dirent: - raise SvnPathNotFound(_('%s not found up to revision %d') - % (path, stop)) + raise SvnPathNotFound( + _('%s not found up to revision %d') % (path, stop) + ) # stat() gives us the previous revision on this line of # development, but it might be in *another module*. Fetch the @@ -750,8 +873,9 @@ self.module = new_module self.reparent(self.module) - progress = self.ui.makeprogress(_('scanning paths'), unit=_('paths'), - total=len(paths)) + progress = self.ui.makeprogress( + _('scanning paths'), unit=_('paths'), total=len(paths) + ) for i, (path, ent) in enumerate(paths): progress.update(i, item=path) entrypath = self.getrelpath(path) @@ -769,10 +893,12 @@ copyfrom_path = self.getrelpath(ent.copyfrom_path, pmodule) if not copyfrom_path: continue - self.ui.debug("copied to %s from %s@%s\n" % - (entrypath, copyfrom_path, ent.copyfrom_rev)) + self.ui.debug( + "copied to %s from %s@%s\n" + % (entrypath, copyfrom_path, ent.copyfrom_rev) + ) copies[self.recode(entrypath)] = self.recode(copyfrom_path) - elif kind == 0: # gone, but had better be a deleted *file* + elif kind == 0: # gone, but had better be a deleted *file* self.ui.debug("gone from %s\n" % ent.copyfrom_rev) pmodule, prevnum = revsplit(parents[0])[1:] parentpath = pmodule + "/" + entrypath @@ -790,8 +916,9 @@ if childpath: removed.add(self.recode(childpath)) else: - self.ui.debug('unknown path in revision %d: %s\n' % - (revnum, path)) + self.ui.debug( + 'unknown path in revision %d: %s\n' % (revnum, path) + ) elif kind == svn.core.svn_node_dir: if ent.action == 'M': # If the directory just had a prop change, @@ -828,14 +955,16 @@ copyfrompath = self.getrelpath(ent.copyfrom_path, pmodule) if not copyfrompath: continue - self.ui.debug("mark %s came from %s:%d\n" - % (path, copyfrompath, ent.copyfrom_rev)) + self.ui.debug( + "mark %s came from %s:%d\n" + % (path, copyfrompath, ent.copyfrom_rev) + ) children = self._iterfiles(ent.copyfrom_path, ent.copyfrom_rev) for childpath in children: childpath = self.getrelpath("/" + childpath, pmodule) if not childpath: continue - copytopath = path + childpath[len(copyfrompath):] + copytopath = path + childpath[len(copyfrompath) :] copytopath = self.getrelpath(copytopath) copies[self.recode(copytopath)] = self.recode(childpath) @@ -853,8 +982,9 @@ """Return the parsed commit object or None, and True if the revision is a branch root. """ - self.ui.debug("parsing revision %d (%d changes)\n" % - (revnum, len(orig_paths))) + self.ui.debug( + "parsing revision %d (%d changes)\n" % (revnum, len(orig_paths)) + ) branched = False rev = self.revid(revnum) @@ -867,13 +997,14 @@ # check whether this revision is the start of a branch or part # of a branch renaming orig_paths = sorted(orig_paths.iteritems()) - root_paths = [(p, e) for p, e in orig_paths - if self.module.startswith(p)] + root_paths = [ + (p, e) for p, e in orig_paths if self.module.startswith(p) + ] if root_paths: path, ent = root_paths[-1] if ent.copyfrom_path: branched = True - newpath = ent.copyfrom_path + self.module[len(path):] + newpath = ent.copyfrom_path + self.module[len(path) :] # ent.copyfrom_rev may not be the actual last revision previd = self.latest(newpath, ent.copyfrom_rev) if previd is not None: @@ -881,8 +1012,9 @@ if prevnum >= self.startrev: parents = [previd] self.ui.note( - _('found parent of branch %s at %d: %s\n') % - (self.module, prevnum, prevmodule)) + _('found parent of branch %s at %d: %s\n') + % (self.module, prevnum, prevmodule) + ) else: self.ui.debug("no copyfrom path, don't know what to do.\n") @@ -917,12 +1049,14 @@ except IndexError: branch = None - cset = commit(author=author, - date=dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'), - desc=log, - parents=parents, - branch=branch, - rev=rev) + cset = commit( + author=author, + date=dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'), + desc=log, + parents=parents, + branch=branch, + rev=rev, + ) self.commits[rev] = cset # The parents list is *shared* among self.paths and the @@ -933,8 +1067,10 @@ self.child_cset = cset return cset, branched - self.ui.note(_('fetching revision log for "%s" from %d to %d\n') % - (self.module, from_revnum, to_revnum)) + self.ui.note( + _('fetching revision log for "%s" from %d to %d\n') + % (self.module, from_revnum, to_revnum) + ) try: firstcset = None @@ -952,8 +1088,9 @@ # revision, do not try to get a parent branch lastonbranch = lastonbranch or revnum == 0 continue - cset, lastonbranch = parselogentry(paths, revnum, author, - date, message) + cset, lastonbranch = parselogentry( + paths, revnum, author, date, message + ) if cset: firstcset = cset if lastonbranch: @@ -976,8 +1113,9 @@ except svn.core.SubversionException as xxx_todo_changeme: (inst, num) = xxx_todo_changeme.args if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: - raise error.Abort(_('svn: branch has no revision %s') - % to_revnum) + raise error.Abort( + _('svn: branch has no revision %s') % to_revnum + ) raise def getfile(self, file, rev): @@ -1000,15 +1138,17 @@ mode = ("svn:executable" in info) and 'x' or '' mode = ("svn:special" in info) and 'l' or mode except svn.core.SubversionException as e: - notfound = (svn.core.SVN_ERR_FS_NOT_FOUND, - svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND) - if e.apr_err in notfound: # File not found + notfound = ( + svn.core.SVN_ERR_FS_NOT_FOUND, + svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND, + ) + if e.apr_err in notfound: # File not found return None, None raise if mode == 'l': link_prefix = "link " if data.startswith(link_prefix): - data = data[len(link_prefix):] + data = data[len(link_prefix) :] return data, mode def _iterfiles(self, path, revnum): @@ -1019,8 +1159,11 @@ entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool) if path: path += '/' - return ((path + p) for p, e in entries.iteritems() - if e.kind == svn.core.svn_node_file) + return ( + (path + p) + for p, e in entries.iteritems() + if e.kind == svn.core.svn_node_file + ) def getrelpath(self, path, module=None): if module is None: @@ -1032,7 +1175,7 @@ # "/CMFPlone/branches/Plone-2_0-branch/tests/PloneTestCase.py" # that is to say "tests/PloneTestCase.py" if path.startswith(module): - relative = path.rstrip('/')[len(module):] + relative = path.rstrip('/')[len(module) :] if relative.startswith('/'): return relative[1:] elif relative == '': @@ -1054,8 +1197,15 @@ if module is not None: self.reparent(prevmodule) - def _getlog(self, paths, start, end, limit=0, discover_changed_paths=True, - strict_node_history=False): + def _getlog( + self, + paths, + start, + end, + limit=0, + discover_changed_paths=True, + strict_node_history=False, + ): # Normalize path names, svn >= 1.5 only wants paths relative to # supplied URL relpaths = [] @@ -1063,8 +1213,15 @@ if not p.startswith('/'): p = self.module + '/' + p relpaths.append(p.strip('/')) - args = [self.baseurl, relpaths, start, end, limit, - discover_changed_paths, strict_node_history] + args = [ + self.baseurl, + relpaths, + start, + end, + limit, + discover_changed_paths, + strict_node_history, + ] # developer config: convert.svn.debugsvnlog if not self.ui.configbool('convert', 'svn.debugsvnlog'): return directlogstream(*args) @@ -1076,10 +1233,15 @@ try: stdin.close() except IOError: - raise error.Abort(_('Mercurial failed to run itself, check' - ' hg executable is in PATH')) + raise error.Abort( + _( + 'Mercurial failed to run itself, check' + ' hg executable is in PATH' + ) + ) return logstream(stdout) + pre_revprop_change = b'''#!/bin/sh REPOS="$1" @@ -1096,6 +1258,7 @@ exit 1 ''' + class svn_sink(converter_sink, commandline): commit_re = re.compile(br'Committed revision (\d+).', re.M) uuid_re = re.compile(br'Repository UUID:\s*(\S+)', re.M) @@ -1137,8 +1300,10 @@ path = os.path.realpath(path) if os.path.isdir(os.path.dirname(path)): if not os.path.exists(os.path.join(path, 'db', 'fs-type')): - ui.status(_("initializing svn repository '%s'\n") % - os.path.basename(path)) + ui.status( + _("initializing svn repository '%s'\n") + % os.path.basename(path) + ) commandline(ui, 'svnadmin').run0('create', path) created = path path = util.normpath(path) @@ -1146,10 +1311,13 @@ path = '/' + path path = 'file://' + path - wcpath = os.path.join(encoding.getcwd(), os.path.basename(path) + - '-wc') - ui.status(_("initializing svn working copy '%s'\n") - % os.path.basename(wcpath)) + wcpath = os.path.join( + encoding.getcwd(), os.path.basename(path) + '-wc' + ) + ui.status( + _("initializing svn working copy '%s'\n") + % os.path.basename(wcpath) + ) self.run0('checkout', path, wcpath) self.wc = wcpath @@ -1186,8 +1354,9 @@ for n in e.childNodes: if n.nodeType != n.ELEMENT_NODE or n.tagName != r'name': continue - name = r''.join(c.data for c in n.childNodes - if c.nodeType == c.TEXT_NODE) + name = r''.join( + c.data for c in n.childNodes if c.nodeType == c.TEXT_NODE + ) # Entries are compared with names coming from # mercurial, so bytes with undefined encoding. Our # best bet is to assume they are in local @@ -1233,7 +1402,8 @@ exists = os.path.lexists(wdest) if exists: fd, tempname = pycompat.mkstemp( - prefix='hg-copy-', dir=os.path.dirname(wdest)) + prefix='hg-copy-', dir=os.path.dirname(wdest) + ) os.close(fd) os.unlink(tempname) os.rename(wdest, tempname) @@ -1259,8 +1429,9 @@ return dirs def add_dirs(self, files): - add_dirs = [d for d in sorted(self.dirs_of(files)) - if d not in self.manifest] + add_dirs = [ + d for d in sorted(self.dirs_of(files)) if d not in self.manifest + ] if add_dirs: self.manifest.update(add_dirs) self.xargs(add_dirs, 'add', non_recursive=True, quiet=True) @@ -1279,8 +1450,9 @@ def revid(self, rev): return "svn:%s@%s" % (self.uuid, rev) - def putcommit(self, files, copies, parents, commit, source, revmap, full, - cleanp2): + def putcommit( + self, files, copies, parents, commit, source, revmap, full, cleanp2 + ): for parent in parents: try: return self.revid(self.childmap[parent]) @@ -1325,10 +1497,12 @@ fp.write(util.tonativeeol(commit.desc)) fp.close() try: - output = self.run0('commit', - username=stringutil.shortuser(commit.author), - file=messagefile, - encoding='utf-8') + output = self.run0( + 'commit', + username=stringutil.shortuser(commit.author), + file=messagefile, + encoding='utf-8', + ) try: rev = self.commit_re.search(output).group(1) except AttributeError: @@ -1338,11 +1512,21 @@ self.ui.warn(output) raise error.Abort(_('unable to cope with svn output')) if commit.rev: - self.run('propset', 'hg:convert-rev', commit.rev, - revprop=True, revision=rev) + self.run( + 'propset', + 'hg:convert-rev', + commit.rev, + revprop=True, + revision=rev, + ) if commit.branch and commit.branch != 'default': - self.run('propset', 'hg:convert-branch', commit.branch, - revprop=True, revision=rev) + self.run( + 'propset', + 'hg:convert-branch', + commit.branch, + revprop=True, + revision=rev, + ) for parent in parents: self.addchild(parent, rev) return self.revid(rev) @@ -1363,6 +1547,10 @@ # repository and childmap would not list all revisions. Too bad. if rev in self.childmap: return True - raise error.Abort(_('splice map revision %s not found in subversion ' - 'child map (revision lookups are not implemented)') - % rev) + raise error.Abort( + _( + 'splice map revision %s not found in subversion ' + 'child map (revision lookups are not implemented)' + ) + % rev + )