subversion.py
1167 lines
| 45.3 KiB
| text/x-python
|
PythonLexer
|
r4765 | # Subversion 1.4/1.5 Python API backend | ||
# | ||||
# Copyright(C) 2007 Daniel Holth et al | ||||
|
r4925 | # | ||
# Configuration options: | ||||
# | ||||
# convert.svn.trunk | ||||
# Relative path to the trunk (default: "trunk") | ||||
# convert.svn.branches | ||||
# Relative path to tree of branches (default: "branches") | ||||
|
r5462 | # convert.svn.tags | ||
# Relative path to tree of tags (default: "tags") | ||||
|
r4925 | # | ||
# Set these in a hgrc, or on the command line as follows: | ||||
# | ||||
# hg convert --config convert.svn.trunk=wackoname [...] | ||||
|
r4765 | |||
import locale | ||||
|
r4946 | import os | ||
|
r5513 | import re | ||
|
r5139 | import sys | ||
|
r4946 | import cPickle as pickle | ||
|
r5513 | import tempfile | ||
|
r7074 | import urllib | ||
|
r5513 | |||
from mercurial import strutil, util | ||||
from mercurial.i18n import _ | ||||
|
r4765 | |||
# Subversion stuff. Works best with very recent Python SVN bindings | ||||
# e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing | ||||
# these bindings. | ||||
from cStringIO import StringIO | ||||
|
r7447 | from common import NoRepo, MissingTool, commit, encodeargs, decodeargs | ||
from common import commandline, converter_source, converter_sink, mapfile | ||||
|
r4766 | |||
try: | ||||
from svn.core import SubversionException, Pool | ||||
|
r5010 | import svn | ||
import svn.client | ||||
|
r4766 | import svn.core | ||
import svn.ra | ||||
import svn.delta | ||||
import transport | ||||
except ImportError: | ||||
pass | ||||
|
r4765 | |||
|
r7381 | class SvnPathNotFound(Exception): | ||
pass | ||||
|
r5008 | def geturl(path): | ||
|
r5010 | try: | ||
|
r5020 | return svn.client.url_from_path(svn.core.svn_path_canonicalize(path)) | ||
|
r5010 | except SubversionException: | ||
pass | ||||
|
r5008 | if os.path.isdir(path): | ||
|
r5793 | path = os.path.normpath(os.path.abspath(path)) | ||
if os.name == 'nt': | ||||
|
r5842 | path = '/' + util.normpath(path) | ||
|
r7074 | return 'file://%s' % urllib.quote(path) | ||
|
r5008 | return path | ||
|
r5117 | def optrev(number): | ||
optrev = svn.core.svn_opt_revision_t() | ||||
optrev.kind = svn.core.svn_opt_revision_number | ||||
optrev.value.number = number | ||||
return optrev | ||||
|
r4946 | class changedpath(object): | ||
def __init__(self, p): | ||||
self.copyfrom_path = p.copyfrom_path | ||||
self.copyfrom_rev = p.copyfrom_rev | ||||
self.action = p.action | ||||
|
r5127 | 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): | ||||
if orig_paths is not None: | ||||
for k, v in orig_paths.iteritems(): | ||||
orig_paths[k] = changedpath(v) | ||||
pickle.dump((orig_paths, revnum, author, date, message), | ||||
|
r5143 | fp, protocol) | ||
|
r5127 | 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) | ||||
|
r5140 | except SubversionException, (inst, num): | ||
|
r5127 | pickle.dump(num, fp, protocol) | ||
|
r5873 | except IOError: | ||
# Caller may interrupt the iteration | ||||
pickle.dump(None, fp, protocol) | ||||
|
r5127 | else: | ||
pickle.dump(None, fp, protocol) | ||||
fp.close() | ||||
|
r6397 | # With large history, cleanup process goes crazy and suddenly | ||
# consumes *huge* amount of memory. The output file being closed, | ||||
# there is no need for clean termination. | ||||
os._exit(0) | ||||
|
r5127 | |||
|
r5139 | def debugsvnlog(ui, **opts): | ||
"""Fetch SVN log in a subprocess and channel them back to parent to | ||||
avoid memory collection issues. | ||||
""" | ||||
util.set_binary(sys.stdin) | ||||
util.set_binary(sys.stdout) | ||||
args = decodeargs(sys.stdin.read()) | ||||
get_log_child(sys.stdout, *args) | ||||
|
r5873 | class logstream: | ||
"""Interruptible revision log iterator.""" | ||||
def __init__(self, stdout): | ||||
self._stdout = stdout | ||||
def __iter__(self): | ||||
while True: | ||||
entry = pickle.load(self._stdout) | ||||
try: | ||||
orig_paths, revnum, author, date, message = entry | ||||
except: | ||||
if entry is None: | ||||
break | ||||
raise SubversionException("child raised exception", entry) | ||||
yield entry | ||||
def close(self): | ||||
if self._stdout: | ||||
self._stdout.close() | ||||
self._stdout = None | ||||
|
r4765 | # SVN conversion code stolen from bzr-svn and tailor | ||
|
r5876 | # | ||
# Subversion looks like a versioned filesystem, branches structures | ||||
# are defined by conventions and not enforced by the tool. First, | ||||
# we define the potential branches (modules) as "trunk" and "branches" | ||||
# children directories. Revisions are then identified by their | ||||
# module and revision number (and a repository identifier). | ||||
# | ||||
# The revision graph is really a tree (or a forest). By default, a | ||||
# revision parent is the previous revision in the same module. If the | ||||
# module directory is copied/moved from another module then the | ||||
# revision is the module root and its parent the source revision in | ||||
# the parent module. A revision has at most one parent. | ||||
# | ||||
|
r5438 | class svn_source(converter_source): | ||
|
r4766 | def __init__(self, ui, url, rev=None): | ||
|
r5438 | super(svn_source, self).__init__(ui, url, rev=rev) | ||
|
r4807 | |||
|
r4766 | try: | ||
SubversionException | ||||
except NameError: | ||||
|
r7447 | raise MissingTool(_('Subversion python bindings could not be loaded')) | ||
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) | ||||
except AttributeError: | ||||
raise MissingTool(_('Subversion python bindings are too old, 1.4 ' | ||||
'or later required')) | ||||
|
r4766 | |||
|
r4765 | self.encoding = locale.getpreferredencoding() | ||
|
r4813 | self.lastrevs = {} | ||
|
r4766 | latest = None | ||
|
r4765 | try: | ||
# Support file://path@rev syntax. Useful e.g. to convert | ||||
# deleted branches. | ||||
|
r4927 | at = url.rfind('@') | ||
if at >= 0: | ||||
latest = int(url[at+1:]) | ||||
url = url[:at] | ||||
|
r7874 | except ValueError: | ||
|
r4766 | pass | ||
|
r5008 | self.url = geturl(url) | ||
|
r4765 | self.encoding = 'UTF-8' # Subversion is always nominal UTF-8 | ||
try: | ||||
|
r5008 | self.transport = transport.SvnRaTransport(url=self.url) | ||
|
r4765 | self.ra = self.transport.ra | ||
|
r4946 | self.ctx = self.transport.client | ||
|
r7074 | self.baseurl = svn.ra.get_repos_root(self.ra) | ||
|
r6538 | # Module is either empty or a repository path starting with | ||
# a slash and not ending with a slash. | ||||
|
r7074 | self.module = urllib.unquote(self.url[len(self.baseurl):]) | ||
|
r6847 | self.prevmodule = None | ||
|
r5957 | self.rootmodule = self.module | ||
|
r4765 | self.commits = {} | ||
|
r5121 | self.paths = {} | ||
|
r4765 | self.uuid = svn.ra.get_uuid(self.ra).decode(self.encoding) | ||
except SubversionException, e: | ||||
|
r5437 | ui.print_exc() | ||
|
r5521 | raise NoRepo("%s does not look like a Subversion repo" % self.url) | ||
|
r4765 | |||
|
r5145 | if rev: | ||
try: | ||||
latest = int(rev) | ||||
except ValueError: | ||||
|
r6956 | raise util.Abort(_('svn: revision %s is not an integer') % rev) | ||
|
r5145 | |||
|
r6173 | self.startrev = self.ui.config('convert', 'svn.startrev', default=0) | ||
try: | ||||
self.startrev = int(self.startrev) | ||||
if self.startrev < 0: | ||||
self.startrev = 0 | ||||
except ValueError: | ||||
|
r6210 | raise util.Abort(_('svn: start revision %s is not an integer') | ||
|
r6173 | % self.startrev) | ||
|
r4765 | try: | ||
self.get_blacklist() | ||||
except IOError, e: | ||||
pass | ||||
|
r5955 | self.head = self.latest(self.module, latest) | ||
|
r5957 | if not self.head: | ||
raise util.Abort(_('no revision found in module %s') % | ||||
self.module.encode(self.encoding)) | ||||
|
r5955 | self.last_changed = self.revnum(self.head) | ||
|
r6210 | |||
|
r5382 | self._changescache = None | ||
|
r4765 | |||
|
r5554 | if os.path.exists(os.path.join(url, '.svn/entries')): | ||
self.wc = url | ||||
else: | ||||
self.wc = None | ||||
self.convertfp = None | ||||
|
r5510 | def setrevmap(self, revmap): | ||
|
r4840 | lastrevs = {} | ||
|
r5511 | for revid in revmap.iterkeys(): | ||
|
r4840 | uuid, module, revnum = self.revsplit(revid) | ||
lastrevnum = lastrevs.setdefault(module, revnum) | ||||
if revnum > lastrevnum: | ||||
lastrevs[module] = revnum | ||||
self.lastrevs = lastrevs | ||||
|
r4925 | def exists(self, path, optrev): | ||
try: | ||||
|
r7074 | svn.client.ls(self.url.rstrip('/') + '/' + urllib.quote(path), | ||
|
r4925 | optrev, False, self.ctx) | ||
|
r5461 | return True | ||
|
r4925 | except SubversionException, err: | ||
|
r5461 | return False | ||
|
r4925 | |||
|
r4840 | def getheads(self): | ||
|
r5854 | |||
|
r6491 | def isdir(path, revnum): | ||
|
r6848 | kind = self._checkpath(path, revnum) | ||
|
r6491 | return kind == svn.core.svn_node_dir | ||
|
r5854 | def getcfgpath(name, rev): | ||
cfgpath = self.ui.config('convert', 'svn.' + name) | ||||
|
r6172 | if cfgpath is not None and cfgpath.strip() == '': | ||
return None | ||||
|
r5854 | path = (cfgpath or name).strip('/') | ||
if not self.exists(path, rev): | ||||
if cfgpath: | ||||
raise util.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 | ||||
|
r5117 | rev = optrev(self.last_changed) | ||
|
r5854 | oldmodule = '' | ||
trunk = getcfgpath('trunk', rev) | ||||
|
r6400 | self.tags = getcfgpath('tags', rev) | ||
|
r5854 | branches = getcfgpath('branches', rev) | ||
# If the project has a trunk or branches, we will extract heads | ||||
# from them. We keep the project root otherwise. | ||||
if trunk: | ||||
oldmodule = self.module or '' | ||||
|
r4925 | self.module += '/' + trunk | ||
|
r5955 | self.head = self.latest(self.module, self.last_changed) | ||
|
r5957 | if not self.head: | ||
raise util.Abort(_('no revision found in module %s') % | ||||
self.module.encode(self.encoding)) | ||||
|
r5854 | |||
# First head in the list is the module's head | ||||
self.heads = [self.head] | ||||
|
r6400 | if self.tags is not None: | ||
self.tags = '%s/%s' % (oldmodule , (self.tags or 'tags')) | ||||
|
r5854 | |||
# Check if branches bring a few more heads to the list | ||||
if branches: | ||||
rpath = self.url.strip('/') | ||||
|
r7184 | branchnames = svn.client.ls(rpath + '/' + urllib.quote(branches), | ||
|
r7074 | rev, False, self.ctx) | ||
|
r4925 | for branch in branchnames.keys(): | ||
|
r5854 | module = '%s/%s/%s' % (oldmodule, branches, branch) | ||
|
r6491 | if not isdir(module, self.last_changed): | ||
continue | ||||
|
r5955 | brevid = self.latest(module, self.last_changed) | ||
|
r5957 | if not brevid: | ||
self.ui.note(_('ignoring empty branch %s\n') % | ||||
branch.encode(self.encoding)) | ||||
continue | ||||
|
r6956 | self.ui.note(_('found branch %s at %d\n') % | ||
|
r5955 | (branch, self.revnum(brevid))) | ||
self.heads.append(brevid) | ||||
|
r5462 | |||
|
r6173 | if self.startrev and self.heads: | ||
if len(self.heads) > 1: | ||||
raise util.Abort(_('svn: start revision is not supported with ' | ||||
'with more than one branch')) | ||||
revnum = self.revnum(self.heads[0]) | ||||
if revnum < self.startrev: | ||||
|
r6210 | raise util.Abort(_('svn: no revision found after start revision %d') | ||
|
r6173 | % self.startrev) | ||
|
r4840 | return self.heads | ||
def getfile(self, file, rev): | ||||
data, mode = self._getfile(file, rev) | ||||
self.modecache[(file, rev)] = mode | ||||
return data | ||||
|
r4957 | def getmode(self, file, rev): | ||
|
r4840 | return self.modecache[(file, rev)] | ||
def getchanges(self, rev): | ||||
|
r5382 | if self._changescache and self._changescache[0] == rev: | ||
return self._changescache[1] | ||||
self._changescache = None | ||||
|
r4840 | self.modecache = {} | ||
|
r5121 | (paths, parents) = self.paths[rev] | ||
|
r5956 | if parents: | ||
files, copies = self.expandpaths(rev, paths, parents) | ||||
else: | ||||
# Perform a full checkout on roots | ||||
uuid, module, revnum = self.revsplit(rev) | ||||
|
r7184 | entries = svn.client.ls(self.baseurl + urllib.quote(module), | ||
|
r7074 | optrev(revnum), True, self.ctx) | ||
|
r6210 | files = [n for n,e in entries.iteritems() | ||
|
r5956 | if e.kind == svn.core.svn_node_file] | ||
copies = {} | ||||
|
r5121 | files.sort() | ||
files = zip(files, [rev] * len(files)) | ||||
|
r4840 | # caller caches the result, so free it here to release memory | ||
|
r5121 | del self.paths[rev] | ||
return (files, copies) | ||||
|
r4840 | |||
|
r5382 | def getchangedfiles(self, rev, i): | ||
changes = self.getchanges(rev) | ||||
self._changescache = (rev, changes) | ||||
return [f[0] for f in changes[0]] | ||||
|
r4840 | def getcommit(self, rev): | ||
if rev not in self.commits: | ||||
uuid, module, revnum = self.revsplit(rev) | ||||
self.module = module | ||||
self.reparent(module) | ||||
|
r5875 | # We assume that: | ||
# - requests for revisions after "stop" come from the | ||||
# revision graph backward traversal. Cache all of them | ||||
# down to stop, they will be used eventually. | ||||
# - requests for revisions before "stop" come to get | ||||
# isolated branches parents. Just fetch what is needed. | ||||
|
r4840 | stop = self.lastrevs.get(module, 0) | ||
|
r5875 | if revnum < stop: | ||
stop = revnum + 1 | ||||
|
r5871 | self._fetch_revisions(revnum, stop) | ||
|
r4840 | commit = self.commits[rev] | ||
# caller caches the result, so free it here to release memory | ||||
del self.commits[rev] | ||||
return commit | ||||
def gettags(self): | ||||
tags = {} | ||||
|
r6172 | if self.tags is None: | ||
return tags | ||||
|
r6210 | |||
|
r6399 | # svn tags are just a convention, project branches left in a | ||
# 'tags' directory. There is no other relationship than | ||||
# ancestry, which is expensive to discover and makes them hard | ||||
# to update incrementally. Worse, past revisions may be | ||||
# referenced by tags far away in the future, requiring a deep | ||||
# history traversal on every calculation. Current code | ||||
# performs a single backward traversal, tracking moves within | ||||
# the tags directory (tag renaming) and recording a new tag | ||||
# everytime a project is copied from outside the tags | ||||
# directory. It also lists deleted tags, this behaviour may | ||||
# change in the future. | ||||
pendings = [] | ||||
tagspath = self.tags | ||||
start = svn.ra.get_latest_revnum(self.ra) | ||||
|
r4949 | try: | ||
|
r6850 | for entry in self._getlog([self.tags], start, self.startrev): | ||
|
r6399 | origpaths, revnum, author, date, message = entry | ||
|
r6493 | copies = [(e.copyfrom_path, e.copyfrom_rev, p) for p, e | ||
|
r6399 | in origpaths.iteritems() if e.copyfrom_path] | ||
copies.sort() | ||||
# Apply moves/copies from more specific to general | ||||
copies.reverse() | ||||
srctagspath = tagspath | ||||
if copies and copies[-1][2] == tagspath: | ||||
# Track tags directory moves | ||||
srctagspath = copies.pop()[0] | ||||
for source, sourcerev, dest in copies: | ||||
if not dest.startswith(tagspath + '/'): | ||||
|
r4949 | continue | ||
|
r6399 | for tag in pendings: | ||
if tag[0].startswith(dest): | ||||
tagpath = source + tag[0][len(dest):] | ||||
tag[:2] = [tagpath, sourcerev] | ||||
break | ||||
else: | ||||
pendings.append([source, sourcerev, dest.split('/')[-1]]) | ||||
# Tell tag renamings from tag creations | ||||
remainings = [] | ||||
for source, sourcerev, tagname in pendings: | ||||
if source.startswith(srctagspath): | ||||
remainings.append([source, sourcerev, tagname]) | ||||
continue | ||||
# From revision may be fake, get one with changes | ||||
|
r7381 | try: | ||
tagid = self.latest(source, sourcerev) | ||||
if tagid: | ||||
tags[tagname] = tagid | ||||
except SvnPathNotFound: | ||||
# It happens when we are following directories we assumed | ||||
# were copied with their parents but were really created | ||||
# in the tag directory. | ||||
pass | ||||
|
r6399 | pendings = remainings | ||
tagspath = srctagspath | ||||
|
r5140 | except SubversionException, (inst, num): | ||
|
r6956 | self.ui.note(_('no tags found at revision %d\n') % start) | ||
|
r4946 | return tags | ||
|
r4840 | |||
|
r5554 | def converted(self, rev, destrev): | ||
if not self.wc: | ||||
return | ||||
if self.convertfp is None: | ||||
self.convertfp = open(os.path.join(self.wc, '.svn', 'hg-shamap'), | ||||
'a') | ||||
self.convertfp.write('%s %d\n' % (destrev, self.revnum(rev))) | ||||
self.convertfp.flush() | ||||
|
r4840 | # -- helper functions -- | ||
|
r4810 | def revid(self, revnum, module=None): | ||
|
r4795 | if not module: | ||
module = self.module | ||||
|
r5287 | return u"svn:%s%s@%s" % (self.uuid, module.decode(self.encoding), | ||
revnum) | ||||
|
r4774 | |||
def revnum(self, rev): | ||||
return int(rev.split('@')[-1]) | ||||
|
r4789 | |||
|
r4794 | def revsplit(self, rev): | ||
|
r7857 | url, revnum = strutil.rsplit(rev.encode(self.encoding), '@', 1) | ||
|
r4794 | revnum = int(revnum) | ||
parts = url.split('/', 1) | ||||
uuid = parts.pop(0)[4:] | ||||
|
r4797 | mod = '' | ||
|
r4794 | if parts: | ||
|
r4797 | mod = '/' + parts[0] | ||
|
r4794 | return uuid, mod, revnum | ||
|
r4790 | def latest(self, path, stop=0): | ||
|
r5955 | """Find the latest revid affecting path, up to stop. It may return | ||
a revision in a different module, since a branch may be moved without | ||||
|
r5957 | a change being reported. Return None if computed module does not | ||
belong to rootmodule subtree. | ||||
|
r5955 | """ | ||
|
r6281 | if not path.startswith(self.rootmodule): | ||
# Requests on foreign branches may be forbidden at server level | ||||
self.ui.debug(_('ignoring foreign branch %r\n') % path) | ||||
return None | ||||
|
r4789 | if not stop: | ||
stop = svn.ra.get_latest_revnum(self.ra) | ||||
try: | ||||
|
r6847 | prevmodule = self.reparent('') | ||
|
r4789 | dirent = svn.ra.stat(self.ra, path.strip('/'), stop) | ||
|
r6847 | self.reparent(prevmodule) | ||
|
r4789 | except SubversionException: | ||
dirent = None | ||||
if not dirent: | ||||
|
r7381 | raise SvnPathNotFound(_('%s not found up to revision %d') % (path, stop)) | ||
|
r4789 | |||
|
r5955 | # stat() gives us the previous revision on this line of development, but | ||
# it might be in *another module*. Fetch the log and detect renames down | ||||
# to the latest revision. | ||||
|
r6850 | stream = self._getlog([path], stop, dirent.created_rev) | ||
|
r5955 | try: | ||
for entry in stream: | ||||
paths, revnum, author, date, message = entry | ||||
if revnum <= dirent.created_rev: | ||||
break | ||||
for p in paths: | ||||
if not path.startswith(p) or not paths[p].copyfrom_path: | ||||
continue | ||||
newpath = paths[p].copyfrom_path + path[len(p):] | ||||
|
r6956 | self.ui.debug(_("branch renamed from %s to %s at %d\n") % | ||
|
r5955 | (path, newpath, revnum)) | ||
path = newpath | ||||
break | ||||
finally: | ||||
stream.close() | ||||
|
r5957 | if not path.startswith(self.rootmodule): | ||
self.ui.debug(_('ignoring foreign branch %r\n') % path) | ||||
return None | ||||
|
r5955 | return self.revid(dirent.created_rev, path) | ||
|
r4789 | |||
|
r4765 | def get_blacklist(self): | ||
"""Avoid certain revision numbers. | ||||
It is not uncommon for two nearby revisions to cancel each other | ||||
out, e.g. 'I copied trunk into a subdirectory of itself instead | ||||
of making a branch'. The converted repository is significantly | ||||
smaller if we ignore such revisions.""" | ||||
|
r5276 | self.blacklist = util.set() | ||
|
r4765 | blacklist = self.blacklist | ||
for line in file("blacklist.txt", "r"): | ||||
if not line.startswith("#"): | ||||
try: | ||||
svn_rev = int(line.strip()) | ||||
blacklist.add(svn_rev) | ||||
except ValueError, e: | ||||
pass # not an integer or a comment | ||||
def is_blacklisted(self, svn_rev): | ||||
return svn_rev in self.blacklist | ||||
def reparent(self, module): | ||||
|
r6847 | """Reparent the svn transport and return the previous parent.""" | ||
if self.prevmodule == module: | ||||
return module | ||||
|
r7074 | svnurl = self.baseurl + urllib.quote(module) | ||
|
r6847 | prevmodule = self.prevmodule | ||
if prevmodule is None: | ||||
prevmodule = '' | ||||
|
r7075 | self.ui.debug(_("reparent to %s\n") % svnurl) | ||
|
r7074 | svn.ra.reparent(self.ra, svnurl) | ||
|
r6847 | self.prevmodule = module | ||
return prevmodule | ||||
|
r4765 | |||
|
r5120 | def expandpaths(self, rev, paths, parents): | ||
entries = [] | ||||
copyfrom = {} # Map of entrypath, revision for finding source of deleted revisions. | ||||
copies = {} | ||||
|
r5872 | new_module, revnum = self.revsplit(rev)[1:] | ||
if new_module != self.module: | ||||
self.module = new_module | ||||
self.reparent(self.module) | ||||
|
r5121 | |||
|
r5120 | for path, ent in paths: | ||
|
r6539 | entrypath = self.getrelpath(path) | ||
|
r5120 | entry = entrypath.decode(self.encoding) | ||
|
r6848 | kind = self._checkpath(entrypath, revnum) | ||
|
r5120 | if kind == svn.core.svn_node_file: | ||
entries.append(self.recode(entry)) | ||||
|
r6546 | if not ent.copyfrom_path or not parents: | ||
|
r6544 | continue | ||
|
r6546 | # Copy sources not in parent revisions cannot be represented, | ||
# ignore their origin for now | ||||
pmodule, prevnum = self.revsplit(parents[0])[1:] | ||||
if ent.copyfrom_rev < prevnum: | ||||
continue | ||||
copyfrom_path = self.getrelpath(ent.copyfrom_path, pmodule) | ||||
|
r6544 | if not copyfrom_path: | ||
continue | ||||
|
r6956 | self.ui.debug(_("copied to %s from %s@%s\n") % | ||
|
r6544 | (entrypath, copyfrom_path, ent.copyfrom_rev)) | ||
|
r6546 | copies[self.recode(entry)] = self.recode(copyfrom_path) | ||
|
r5120 | elif kind == 0: # gone, but had better be a deleted *file* | ||
|
r6956 | self.ui.debug(_("gone from %s\n") % ent.copyfrom_rev) | ||
|
r5120 | |||
# if a branch is created but entries are removed in the same | ||||
# changeset, get the right fromrev | ||||
|
r5872 | # parents cannot be empty here, you cannot remove things from | ||
# a root revision. | ||||
uuid, old_module, fromrev = self.revsplit(parents[0]) | ||||
|
r5120 | |||
|
r6539 | basepath = old_module + "/" + self.getrelpath(path) | ||
entrypath = basepath | ||||
|
r5120 | |||
def lookup_parts(p): | ||||
rc = None | ||||
parts = p.split("/") | ||||
for i in range(len(parts)): | ||||
part = "/".join(parts[:i]) | ||||
info = part, copyfrom.get(part, None) | ||||
if info[1] is not None: | ||||
|
r7599 | self.ui.debug(_("found parent directory %s\n") % info[1]) | ||
|
r5120 | rc = info | ||
return rc | ||||
|
r6956 | self.ui.debug(_("base, entry %s %s\n") % (basepath, entrypath)) | ||
|
r5120 | |||
frompath, froment = lookup_parts(entrypath) or (None, revnum - 1) | ||||
# need to remove fragment from lookup_parts and replace with copyfrom_path | ||||
if frompath is not None: | ||||
|
r6956 | self.ui.debug(_("munge-o-matic\n")) | ||
|
r5120 | self.ui.debug(entrypath + '\n') | ||
self.ui.debug(entrypath[len(frompath):] + '\n') | ||||
entrypath = froment.copyfrom_path + entrypath[len(frompath):] | ||||
fromrev = froment.copyfrom_rev | ||||
|
r7599 | self.ui.debug(_("info: %s %s %s %s\n") % (frompath, froment, ent, entrypath)) | ||
|
r5120 | |||
|
r5880 | # We can avoid the reparent calls if the module has not changed | ||
# but it probably does not worth the pain. | ||||
|
r6847 | prevmodule = self.reparent('') | ||
|
r5880 | fromkind = svn.ra.check_path(self.ra, entrypath.strip('/'), fromrev) | ||
|
r6847 | self.reparent(prevmodule) | ||
|
r6210 | |||
|
r5120 | if fromkind == svn.core.svn_node_file: # a deleted file | ||
entries.append(self.recode(entry)) | ||||
elif fromkind == svn.core.svn_node_dir: | ||||
# print "Deleted/moved non-file:", revnum, path, ent | ||||
# children = self._find_children(path, revnum - 1) | ||||
# print "find children %s@%d from %d action %s" % (path, revnum, ent.copyfrom_rev, ent.action) | ||||
# Sometimes this is tricky. For example: in | ||||
# The Subversion Repository revision 6940 a dir | ||||
# was copied and one of its files was deleted | ||||
# from the new location in the same commit. This | ||||
# code can't deal with that yet. | ||||
if ent.action == 'C': | ||||
children = self._find_children(path, fromrev) | ||||
else: | ||||
oroot = entrypath.strip('/') | ||||
nroot = path.strip('/') | ||||
children = self._find_children(oroot, fromrev) | ||||
children = [s.replace(oroot,nroot) for s in children] | ||||
# Mark all [files, not directories] as deleted. | ||||
for child in children: | ||||
# Can we move a child directory and its | ||||
# parent in the same commit? (probably can). Could | ||||
# cause problems if instead of revnum -1, | ||||
# we have to look in (copyfrom_path, revnum - 1) | ||||
|
r6539 | entrypath = self.getrelpath("/" + child, module=old_module) | ||
|
r5120 | if entrypath: | ||
entry = self.recode(entrypath.decode(self.encoding)) | ||||
if entry in copies: | ||||
# deleted file within a copy | ||||
del copies[entry] | ||||
else: | ||||
entries.append(entry) | ||||
else: | ||||
|
r6956 | self.ui.debug(_('unknown path in revision %d: %s\n') % \ | ||
|
r5120 | (revnum, path)) | ||
elif kind == svn.core.svn_node_dir: | ||||
# Should probably synthesize normal file entries | ||||
# and handle as above to clean up copy/rename handling. | ||||
# If the directory just had a prop change, | ||||
# then we shouldn't need to look for its children. | ||||
|
r5870 | if ent.action == 'M': | ||
continue | ||||
|
r5120 | # Also this could create duplicate entries. Not sure | ||
# whether this will matter. Maybe should make entries a set. | ||||
# print "Changed directory", revnum, path, ent.action, ent.copyfrom_path, ent.copyfrom_rev | ||||
# This will fail if a directory was copied | ||||
# from another branch and then some of its files | ||||
# were deleted in the same transaction. | ||||
|
r6762 | children = util.sort(self._find_children(path, revnum)) | ||
|
r5120 | for child in children: | ||
# Can we move a child directory and its | ||||
# parent in the same commit? (probably can). Could | ||||
# cause problems if instead of revnum -1, | ||||
# we have to look in (copyfrom_path, revnum - 1) | ||||
|
r6539 | entrypath = self.getrelpath("/" + child) | ||
|
r5120 | # print child, self.module, entrypath | ||
if entrypath: | ||||
# Need to filter out directories here... | ||||
|
r6848 | kind = self._checkpath(entrypath, revnum) | ||
|
r5120 | if kind != svn.core.svn_node_dir: | ||
entries.append(self.recode(entrypath)) | ||||
# Copies here (must copy all from source) | ||||
# Probably not a real problem for us if | ||||
# source does not exist | ||||
|
r6543 | if not ent.copyfrom_path or not parents: | ||
|
r6542 | continue | ||
|
r6543 | # Copy sources not in parent revisions cannot be represented, | ||
# ignore their origin for now | ||||
pmodule, prevnum = self.revsplit(parents[0])[1:] | ||||
if ent.copyfrom_rev < prevnum: | ||||
continue | ||||
copyfrompath = ent.copyfrom_path.decode(self.encoding) | ||||
copyfrompath = self.getrelpath(copyfrompath, pmodule) | ||||
|
r6542 | if not copyfrompath: | ||
continue | ||||
copyfrom[path] = ent | ||||
|
r6956 | self.ui.debug(_("mark %s came from %s:%d\n") | ||
|
r6542 | % (path, copyfrompath, ent.copyfrom_rev)) | ||
children = self._find_children(ent.copyfrom_path, ent.copyfrom_rev) | ||||
children.sort() | ||||
for child in children: | ||||
|
r6543 | entrypath = self.getrelpath("/" + child, pmodule) | ||
|
r6542 | if not entrypath: | ||
continue | ||||
entry = entrypath.decode(self.encoding) | ||||
copytopath = path + entry[len(copyfrompath):] | ||||
copytopath = self.getrelpath(copytopath) | ||||
|
r6543 | copies[self.recode(copytopath)] = self.recode(entry, pmodule) | ||
|
r5120 | |||
|
r5883 | return (util.unique(entries), copies) | ||
|
r5120 | |||
|
r5871 | def _fetch_revisions(self, from_revnum, to_revnum): | ||
if from_revnum < to_revnum: | ||||
from_revnum, to_revnum = to_revnum, from_revnum | ||||
|
r4940 | self.child_cset = None | ||
|
r6545 | |||
|
r4946 | def parselogentry(orig_paths, revnum, author, date, message): | ||
|
r6210 | """Return the parsed commit object or None, and True if | ||
|
r5872 | the revision is a branch root. | ||
""" | ||||
|
r6956 | self.ui.debug(_("parsing revision %d (%d changes)\n") % | ||
|
r4946 | (revnum, len(orig_paths))) | ||
|
r4940 | |||
|
r5957 | branched = False | ||
|
r4810 | rev = self.revid(revnum) | ||
|
r4837 | # branch log might return entries for a parent we already have | ||
|
r5871 | |||
if (rev in self.commits or revnum < to_revnum): | ||||
|
r5957 | return None, branched | ||
|
r4837 | |||
|
r5120 | parents = [] | ||
|
r5958 | # check whether this revision is the start of a branch or part | ||
# of a branch renaming | ||||
|
r6762 | orig_paths = util.sort(orig_paths.items()) | ||
|
r5958 | root_paths = [(p,e) for p,e in orig_paths if self.module.startswith(p)] | ||
if root_paths: | ||||
path, ent = root_paths[-1] | ||||
|
r5119 | if ent.copyfrom_path: | ||
|
r5957 | branched = True | ||
|
r5958 | newpath = ent.copyfrom_path + self.module[len(path):] | ||
|
r5119 | # ent.copyfrom_rev may not be the actual last revision | ||
|
r7476 | previd = self.latest(newpath, ent.copyfrom_rev) | ||
|
r5957 | if previd is not None: | ||
prevmodule, prevnum = self.revsplit(previd)[1:] | ||||
|
r6173 | if prevnum >= self.startrev: | ||
parents = [previd] | ||||
|
r6956 | self.ui.note(_('found parent of branch %s at %d: %s\n') % | ||
|
r6173 | (self.module, prevnum, prevmodule)) | ||
|
r5119 | else: | ||
|
r7599 | self.ui.debug(_("no copyfrom path, don't know what to do.\n")) | ||
|
r5119 | |||
|
r5120 | paths = [] | ||
# filter out unrelated paths | ||||
|
r4940 | for path, ent in orig_paths: | ||
|
r6540 | if self.getrelpath(path) is None: | ||
|
r4788 | continue | ||
|
r5120 | paths.append((path, ent)) | ||
|
r4765 | |||
|
r4788 | # Example SVN datetime. Includes microseconds. | ||
# ISO-8601 conformant | ||||
# '2007-01-04T17:35:00.902377Z' | ||||
|
r5617 | date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"]) | ||
|
r4765 | |||
|
r5916 | log = message and self.recode(message) or '' | ||
|
r4788 | author = author and self.recode(author) or '' | ||
|
r5120 | try: | ||
branch = self.module.split("/")[-1] | ||||
if branch == 'trunk': | ||||
branch = '' | ||||
except IndexError: | ||||
branch = None | ||||
|
r4765 | |||
|
r4788 | cset = commit(author=author, | ||
|
r4957 | date=util.datestr(date), | ||
desc=log, | ||||
|
r4795 | parents=parents, | ||
|
r4873 | branch=branch, | ||
rev=rev.encode('utf-8')) | ||||
|
r4788 | |||
|
r4796 | self.commits[rev] = cset | ||
|
r5872 | # The parents list is *shared* among self.paths and the | ||
# commit object. Both will be updated below. | ||||
self.paths[rev] = (paths, cset.parents) | ||||
|
r4796 | if self.child_cset and not self.child_cset.parents: | ||
|
r5872 | self.child_cset.parents[:] = [rev] | ||
|
r4788 | self.child_cset = cset | ||
|
r5957 | return cset, branched | ||
|
r4796 | |||
|
r6956 | self.ui.note(_('fetching revision log for "%s" from %d to %d\n') % | ||
|
r4797 | (self.module, from_revnum, to_revnum)) | ||
|
r4765 | |||
try: | ||||
|
r5871 | firstcset = None | ||
|
r6173 | lastonbranch = False | ||
|
r6850 | stream = self._getlog([self.module], from_revnum, to_revnum) | ||
|
r5873 | try: | ||
for entry in stream: | ||||
paths, revnum, author, date, message = entry | ||||
|
r6173 | if revnum < self.startrev: | ||
lastonbranch = True | ||||
break | ||||
|
r5873 | if self.is_blacklisted(revnum): | ||
|
r6956 | self.ui.note(_('skipping blacklisted revision %d\n') | ||
|
r5873 | % revnum) | ||
continue | ||||
if paths is None: | ||||
|
r6956 | self.ui.debug(_('revision %d has no entries\n') % revnum) | ||
|
r5873 | continue | ||
|
r6210 | cset, lastonbranch = parselogentry(paths, revnum, author, | ||
|
r6173 | date, message) | ||
|
r5873 | if cset: | ||
firstcset = cset | ||||
|
r6173 | if lastonbranch: | ||
|
r5873 | break | ||
finally: | ||||
stream.close() | ||||
|
r5871 | |||
|
r6173 | if not lastonbranch and firstcset and not firstcset.parents: | ||
|
r5871 | # The first revision of the sequence (the last fetched one) | ||
# has invalid parents if not a branch root. Find the parent | ||||
# revision now, if any. | ||||
try: | ||||
firstrevnum = self.revnum(firstcset.rev) | ||||
if firstrevnum > 1: | ||||
latest = self.latest(self.module, firstrevnum - 1) | ||||
|
r5957 | if latest: | ||
firstcset.parents.append(latest) | ||||
|
r7381 | except SvnPathNotFound: | ||
|
r5871 | pass | ||
|
r5140 | except SubversionException, (inst, num): | ||
|
r4765 | if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: | ||
|
r6956 | raise util.Abort(_('svn: branch has no revision %s') % to_revnum) | ||
|
r4765 | raise | ||
def _getfile(self, file, rev): | ||||
# TODO: ra.get_file transmits the whole file instead of diffs. | ||||
mode = '' | ||||
try: | ||||
|
r5872 | new_module, revnum = self.revsplit(rev)[1:] | ||
if self.module != new_module: | ||||
self.module = new_module | ||||
|
r4765 | self.reparent(self.module) | ||
|
r7446 | io = StringIO() | ||
|
r4765 | info = svn.ra.get_file(self.ra, file, revnum, io) | ||
|
r7446 | data = io.getvalue() | ||
# ra.get_files() seems to keep a reference on the input buffer | ||||
# preventing collection. Release it explicitely. | ||||
io.close() | ||||
|
r4765 | if isinstance(info, list): | ||
info = info[-1] | ||||
mode = ("svn:executable" in info) and 'x' or '' | ||||
mode = ("svn:special" in info) and 'l' or mode | ||||
except SubversionException, 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 | ||||
raise IOError() | ||||
raise | ||||
if mode == 'l': | ||||
link_prefix = "link " | ||||
if data.startswith(link_prefix): | ||||
data = data[len(link_prefix):] | ||||
return data, mode | ||||
def _find_children(self, path, revnum): | ||||
|
r5114 | path = path.strip('/') | ||
|
r4765 | pool = Pool() | ||
|
r7074 | rpath = '/'.join([self.baseurl, urllib.quote(path)]).strip('/') | ||
|
r7184 | return ['%s/%s' % (path, x) for x in | ||
|
r7074 | svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool).keys()] | ||
|
r5513 | |||
|
r6539 | def getrelpath(self, path, module=None): | ||
if module is None: | ||||
module = self.module | ||||
# Given the repository url of this wc, say | ||||
# "http://server/plone/CMFPlone/branches/Plone-2_0-branch" | ||||
# extract the "entry" portion (a relative path) from what | ||||
# svn log --xml says, ie | ||||
# "/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):] | ||||
if relative.startswith('/'): | ||||
return relative[1:] | ||||
elif relative == '': | ||||
return relative | ||||
# The path is outside our tracked tree... | ||||
|
r6956 | self.ui.debug(_('%r is not under %r, ignoring\n') % (path, module)) | ||
|
r6539 | return None | ||
|
r6848 | def _checkpath(self, path, revnum): | ||
# ra.check_path does not like leading slashes very much, it leads | ||||
# to PROPFIND subversion errors | ||||
return svn.ra.check_path(self.ra, path.strip('/'), revnum) | ||||
|
r6850 | 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 = [] | ||||
for p in paths: | ||||
if not p.startswith('/'): | ||||
p = self.module + '/' + p | ||||
relpaths.append(p.strip('/')) | ||||
|
r7074 | args = [self.baseurl, relpaths, start, end, limit, discover_changed_paths, | ||
|
r6850 | strict_node_history] | ||
arg = encodeargs(args) | ||||
hgexe = util.hgexecutable() | ||||
cmd = '%s debugsvnlog' % util.shellquote(hgexe) | ||||
|
r7106 | stdin, stdout = util.popen2(cmd, 'b') | ||
|
r6850 | stdin.write(arg) | ||
stdin.close() | ||||
return logstream(stdout) | ||||
|
r5513 | pre_revprop_change = '''#!/bin/sh | ||
REPOS="$1" | ||||
REV="$2" | ||||
USER="$3" | ||||
PROPNAME="$4" | ||||
ACTION="$5" | ||||
if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi | ||||
if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi | ||||
if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi | ||||
echo "Changing prohibited revision property" >&2 | ||||
exit 1 | ||||
''' | ||||
class svn_sink(converter_sink, commandline): | ||||
commit_re = re.compile(r'Committed revision (\d+).', re.M) | ||||
def prerun(self): | ||||
if self.wc: | ||||
os.chdir(self.wc) | ||||
def postrun(self): | ||||
if self.wc: | ||||
os.chdir(self.cwd) | ||||
def join(self, name): | ||||
return os.path.join(self.wc, '.svn', name) | ||||
|
r5760 | |||
|
r5513 | def revmapfile(self): | ||
return self.join('hg-shamap') | ||||
def authorfile(self): | ||||
return self.join('hg-authormap') | ||||
def __init__(self, ui, path): | ||||
converter_sink.__init__(self, ui, path) | ||||
commandline.__init__(self, ui, 'svn') | ||||
self.delete = [] | ||||
|
r5698 | self.setexec = [] | ||
self.delexec = [] | ||||
self.copies = [] | ||||
|
r5513 | self.wc = None | ||
self.cwd = os.getcwd() | ||||
path = os.path.realpath(path) | ||||
created = False | ||||
if os.path.isfile(os.path.join(path, '.svn', 'entries')): | ||||
self.wc = path | ||||
self.run0('update') | ||||
else: | ||||
|
r5535 | wcpath = os.path.join(os.getcwd(), os.path.basename(path) + '-wc') | ||
|
r5513 | if os.path.isdir(os.path.dirname(path)): | ||
if not os.path.exists(os.path.join(path, 'db', 'fs-type')): | ||||
ui.status(_('initializing svn repo %r\n') % | ||||
os.path.basename(path)) | ||||
commandline(ui, 'svnadmin').run0('create', path) | ||||
created = path | ||||
|
r5842 | path = util.normpath(path) | ||
|
r5535 | if not path.startswith('/'): | ||
path = '/' + path | ||||
|
r5513 | path = 'file://' + path | ||
|
r5760 | |||
|
r5513 | ui.status(_('initializing svn wc %r\n') % os.path.basename(wcpath)) | ||
self.run0('checkout', path, wcpath) | ||||
self.wc = wcpath | ||||
self.opener = util.opener(self.wc) | ||||
self.wopener = util.opener(self.wc) | ||||
self.childmap = mapfile(ui, self.join('hg-childmap')) | ||||
|
r5536 | self.is_exec = util.checkexec(self.wc) and util.is_exec or None | ||
|
r5513 | |||
if created: | ||||
hook = os.path.join(created, 'hooks', 'pre-revprop-change') | ||||
fp = open(hook, 'w') | ||||
fp.write(pre_revprop_change) | ||||
fp.close() | ||||
|
r6877 | util.set_flags(hook, False, True) | ||
|
r5513 | |||
|
r5554 | xport = transport.SvnRaTransport(url=geturl(path)) | ||
self.uuid = svn.ra.get_uuid(xport.ra) | ||||
|
r5513 | def wjoin(self, *names): | ||
return os.path.join(self.wc, *names) | ||||
def putfile(self, filename, flags, data): | ||||
if 'l' in flags: | ||||
self.wopener.symlink(data, filename) | ||||
else: | ||||
try: | ||||
if os.path.islink(self.wjoin(filename)): | ||||
os.unlink(filename) | ||||
except OSError: | ||||
pass | ||||
self.wopener(filename, 'w').write(data) | ||||
|
r5536 | |||
if self.is_exec: | ||||
was_exec = self.is_exec(self.wjoin(filename)) | ||||
else: | ||||
# On filesystems not supporting execute-bit, there is no way | ||||
# to know if it is set but asking subversion. Setting it | ||||
# systematically is just as expensive and much simpler. | ||||
was_exec = 'x' not in flags | ||||
|
r6877 | util.set_flags(self.wjoin(filename), False, 'x' in flags) | ||
|
r5513 | if was_exec: | ||
if 'x' not in flags: | ||||
|
r5698 | self.delexec.append(filename) | ||
|
r5513 | else: | ||
if 'x' in flags: | ||||
|
r5698 | self.setexec.append(filename) | ||
def _copyfile(self, source, dest): | ||||
|
r5513 | # SVN's copy command pukes if the destination file exists, but | ||
# our copyfile method expects to record a copy that has | ||||
# already occurred. Cross the semantic gap. | ||||
wdest = self.wjoin(dest) | ||||
exists = os.path.exists(wdest) | ||||
if exists: | ||||
fd, tempname = tempfile.mkstemp( | ||||
prefix='hg-copy-', dir=os.path.dirname(wdest)) | ||||
os.close(fd) | ||||
os.unlink(tempname) | ||||
os.rename(wdest, tempname) | ||||
try: | ||||
self.run0('copy', source, dest) | ||||
finally: | ||||
if exists: | ||||
try: | ||||
os.unlink(wdest) | ||||
except OSError: | ||||
pass | ||||
os.rename(tempname, wdest) | ||||
def dirs_of(self, files): | ||||
|
r6053 | dirs = util.set() | ||
|
r5513 | for f in files: | ||
if os.path.isdir(self.wjoin(f)): | ||||
dirs.add(f) | ||||
for i in strutil.rfindall(f, '/'): | ||||
dirs.add(f[:i]) | ||||
return dirs | ||||
|
r5698 | def add_dirs(self, files): | ||
|
r6762 | add_dirs = [d for d in util.sort(self.dirs_of(files)) | ||
|
r5513 | if not os.path.exists(self.wjoin(d, '.svn', 'entries'))] | ||
if add_dirs: | ||||
|
r5832 | self.xargs(add_dirs, 'add', non_recursive=True, quiet=True) | ||
|
r5698 | return add_dirs | ||
def add_files(self, files): | ||||
|
r5513 | if files: | ||
|
r5832 | self.xargs(files, 'add', quiet=True) | ||
|
r5698 | return files | ||
|
r5760 | |||
|
r5513 | def tidy_dirs(self, names): | ||
|
r6762 | dirs = util.sort(self.dirs_of(names)) | ||
|
r6053 | dirs.reverse() | ||
|
r5513 | deleted = [] | ||
for d in dirs: | ||||
wd = self.wjoin(d) | ||||
if os.listdir(wd) == '.svn': | ||||
self.run0('delete', d) | ||||
deleted.append(d) | ||||
return deleted | ||||
def addchild(self, parent, child): | ||||
self.childmap[parent] = child | ||||
|
r5554 | def revid(self, rev): | ||
return u"svn:%s@%s" % (self.uuid, rev) | ||||
|
r5698 | |||
|
r6716 | def putcommit(self, files, copies, parents, commit, source): | ||
# Apply changes to working copy | ||||
for f, v in files: | ||||
try: | ||||
data = source.getfile(f, v) | ||||
except IOError, inst: | ||||
self.delete.append(f) | ||||
else: | ||||
e = source.getmode(f, v) | ||||
self.putfile(f, e, data) | ||||
if f in copies: | ||||
self.copies.append([copies[f], f]) | ||||
files = [f[0] for f in files] | ||||
|
r5513 | for parent in parents: | ||
try: | ||||
|
r5554 | return self.revid(self.childmap[parent]) | ||
|
r5513 | except KeyError: | ||
pass | ||||
|
r6053 | entries = util.set(self.delete) | ||
|
r5698 | files = util.frozenset(files) | ||
entries.update(self.add_dirs(files.difference(entries))) | ||||
if self.copies: | ||||
for s, d in self.copies: | ||||
self._copyfile(s, d) | ||||
self.copies = [] | ||||
|
r5513 | if self.delete: | ||
|
r5832 | self.xargs(self.delete, 'delete') | ||
|
r5513 | self.delete = [] | ||
entries.update(self.add_files(files.difference(entries))) | ||||
entries.update(self.tidy_dirs(entries)) | ||||
|
r5698 | if self.delexec: | ||
|
r5832 | self.xargs(self.delexec, 'propdel', 'svn:executable') | ||
|
r5698 | self.delexec = [] | ||
if self.setexec: | ||||
|
r5832 | self.xargs(self.setexec, 'propset', 'svn:executable', '*') | ||
|
r5698 | self.setexec = [] | ||
|
r5513 | fd, messagefile = tempfile.mkstemp(prefix='hg-convert-') | ||
fp = os.fdopen(fd, 'w') | ||||
fp.write(commit.desc) | ||||
fp.close() | ||||
try: | ||||
output = self.run0('commit', | ||||
username=util.shortuser(commit.author), | ||||
file=messagefile, | ||||
|
r5790 | encoding='utf-8') | ||
|
r5513 | try: | ||
rev = self.commit_re.search(output).group(1) | ||||
except AttributeError: | ||||
self.ui.warn(_('unexpected svn output:\n')) | ||||
self.ui.warn(output) | ||||
raise util.Abort(_('unable to cope with svn output')) | ||||
if commit.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) | ||||
for parent in parents: | ||||
self.addchild(parent, rev) | ||||
|
r5554 | return self.revid(rev) | ||
|
r5513 | finally: | ||
os.unlink(messagefile) | ||||
def puttags(self, tags): | ||||
self.ui.warn(_('XXX TAGS NOT IMPLEMENTED YET\n')) | ||||