subversion.py
666 lines
| 27.0 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 | ||
|
r5139 | import sys | ||
|
r4946 | import cPickle as pickle | ||
|
r4765 | from mercurial import util | ||
# 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 | ||||
|
r5139 | from common import NoRepo, commit, converter_source, encodeargs, decodeargs | ||
|
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 | |||
|
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): | ||
return 'file://%s' % os.path.normpath(os.path.abspath(path)) | ||||
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) | ||
else: | ||||
pickle.dump(None, fp, protocol) | ||||
fp.close() | ||||
|
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) | ||||
|
r4765 | # SVN conversion code stolen from bzr-svn and tailor | ||
|
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: | ||||
|
r5521 | raise NoRepo('Subversion python bindings could not be loaded') | ||
|
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] | ||||
|
r4765 | except ValueError, e: | ||
|
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 | ||
|
r4765 | self.base = svn.ra.get_repos_root(self.ra) | ||
self.module = self.url[len(self.base):] | ||||
self.modulemap = {} # revision, module | ||||
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: | ||||
raise util.Abort('svn: revision %s is not an integer' % rev) | ||||
|
r4765 | try: | ||
self.get_blacklist() | ||||
except IOError, e: | ||||
pass | ||||
|
r4789 | self.last_changed = self.latest(self.module, latest) | ||
|
r4765 | |||
|
r4810 | self.head = self.revid(self.last_changed) | ||
|
r5382 | self._changescache = None | ||
|
r4765 | |||
|
r5373 | def setrevmap(self, revmap, order): | ||
|
r4840 | lastrevs = {} | ||
for revid in revmap.keys(): | ||||
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: | ||||
|
r5461 | svn.client.ls(self.url.rstrip('/') + '/' + path, | ||
|
r4925 | optrev, False, self.ctx) | ||
|
r5461 | return True | ||
|
r4925 | except SubversionException, err: | ||
|
r5461 | return False | ||
|
r4925 | |||
|
r4840 | def getheads(self): | ||
# detect standard /branches, /tags, /trunk layout | ||||
|
r5117 | rev = optrev(self.last_changed) | ||
|
r4840 | rpath = self.url.strip('/') | ||
|
r4925 | cfgtrunk = self.ui.config('convert', 'svn.trunk') | ||
cfgbranches = self.ui.config('convert', 'svn.branches') | ||||
|
r5462 | cfgtags = self.ui.config('convert', 'svn.tags') | ||
|
r4925 | trunk = (cfgtrunk or 'trunk').strip('/') | ||
branches = (cfgbranches or 'branches').strip('/') | ||||
|
r5462 | tags = (cfgtags or 'tags').strip('/') | ||
if self.exists(trunk, rev) and self.exists(branches, rev) and self.exists(tags, rev): | ||||
self.ui.note('found trunk at %r, branches at %r and tags at %r\n' % | ||||
(trunk, branches, tags)) | ||||
|
r4925 | oldmodule = self.module | ||
self.module += '/' + trunk | ||||
|
r4840 | lt = self.latest(self.module, self.last_changed) | ||
self.head = self.revid(lt) | ||||
self.heads = [self.head] | ||||
|
r5117 | branchnames = svn.client.ls(rpath + '/' + branches, rev, False, | ||
|
r4925 | self.ctx) | ||
for branch in branchnames.keys(): | ||||
if oldmodule: | ||||
|
r5462 | module = oldmodule + '/' + branches + '/' + branch | ||
|
r4925 | else: | ||
module = '/' + branches + '/' + branch | ||||
|
r4840 | brevnum = self.latest(module, self.last_changed) | ||
brev = self.revid(brevnum, module) | ||||
self.ui.note('found branch %s at %d\n' % (branch, brevnum)) | ||||
self.heads.append(brev) | ||||
|
r5462 | |||
if oldmodule: | ||||
self.tags = '%s/%s' % (oldmodule, tags) | ||||
else: | ||||
self.tags = '/%s' % tags | ||||
elif cfgtrunk or cfgbranches or cfgtags: | ||||
raise util.Abort('trunk/branch/tags layout expected, but not found') | ||||
|
r4840 | else: | ||
|
r4925 | self.ui.note('working with one branch\n') | ||
|
r4840 | self.heads = [self.head] | ||
|
r5462 | self.tags = tags | ||
|
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] | ||
files, copies = self.expandpaths(rev, paths, parents) | ||||
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) | ||||
stop = self.lastrevs.get(module, 0) | ||||
self._fetch_revisions(from_revnum=revnum, to_revnum=stop) | ||||
commit = self.commits[rev] | ||||
# caller caches the result, so free it here to release memory | ||||
del self.commits[rev] | ||||
return commit | ||||
|
r4946 | def get_log(self, paths, start, end, limit=0, discover_changed_paths=True, | ||
strict_node_history=False): | ||||
def parent(fp): | ||||
while True: | ||||
entry = pickle.load(fp) | ||||
try: | ||||
orig_paths, revnum, author, date, message = entry | ||||
except: | ||||
if entry is None: | ||||
break | ||||
raise SubversionException("child raised exception", entry) | ||||
yield entry | ||||
|
r5143 | |||
|
r5127 | args = [self.url, paths, start, end, limit, discover_changed_paths, | ||
strict_node_history] | ||||
arg = encodeargs(args) | ||||
hgexe = util.hgexecutable() | ||||
|
r5144 | cmd = '%s debugsvnlog' % util.shellquote(hgexe) | ||
|
r5127 | stdin, stdout = os.popen2(cmd, 'b') | ||
|
r5143 | |||
|
r5127 | stdin.write(arg) | ||
stdin.close() | ||||
|
r4946 | |||
|
r5127 | for p in parent(stdout): | ||
yield p | ||||
|
r4946 | |||
|
r4840 | def gettags(self): | ||
tags = {} | ||||
|
r4949 | start = self.revnum(self.head) | ||
try: | ||||
|
r5462 | for entry in self.get_log([self.tags], 0, start): | ||
|
r4949 | orig_paths, revnum, author, date, message = entry | ||
for path in orig_paths: | ||||
|
r5462 | if not path.startswith(self.tags+'/'): | ||
|
r4949 | continue | ||
ent = orig_paths[path] | ||||
source = ent.copyfrom_path | ||||
rev = ent.copyfrom_rev | ||||
|
r5462 | tag = path.split('/')[-1] | ||
|
r4949 | tags[tag] = self.revid(rev, module=source) | ||
|
r5140 | except SubversionException, (inst, num): | ||
|
r4949 | self.ui.note('no tags found at revision %d\n' % start) | ||
|
r4946 | return tags | ||
|
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): | ||
url, revnum = rev.encode(self.encoding).split('@', 1) | ||||
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): | ||
|
r4789 | 'find the latest revision affecting path, up to stop' | ||
if not stop: | ||||
stop = svn.ra.get_latest_revnum(self.ra) | ||||
try: | ||||
self.reparent('') | ||||
dirent = svn.ra.stat(self.ra, path.strip('/'), stop) | ||||
self.reparent(self.module) | ||||
except SubversionException: | ||||
dirent = None | ||||
if not dirent: | ||||
|
r4925 | raise util.Abort('%s not found up to revision %d' % (path, stop)) | ||
|
r4789 | |||
return dirent.created_rev | ||||
|
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): | ||||
svn_url = self.base + module | ||||
self.ui.debug("reparent to %s\n" % svn_url.encode(self.encoding)) | ||||
svn.ra.reparent(self.ra, svn_url.encode(self.encoding)) | ||||
|
r5120 | def expandpaths(self, rev, paths, parents): | ||
|
r4765 | def get_entry_from_path(path, 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[len(module):] | ||||
if relative.startswith('/'): | ||||
return relative[1:] | ||||
else: | ||||
return relative | ||||
# The path is outside our tracked tree... | ||||
|
r5120 | self.ui.debug('%r is not under %r, ignoring\n' % (path, module)) | ||
|
r4765 | return None | ||
|
r5120 | entries = [] | ||
copyfrom = {} # Map of entrypath, revision for finding source of deleted revisions. | ||||
copies = {} | ||||
revnum = self.revnum(rev) | ||||
|
r5121 | if revnum in self.modulemap: | ||
new_module = self.modulemap[revnum] | ||||
if new_module != self.module: | ||||
self.module = new_module | ||||
self.reparent(self.module) | ||||
|
r5120 | for path, ent in paths: | ||
entrypath = get_entry_from_path(path, module=self.module) | ||||
entry = entrypath.decode(self.encoding) | ||||
kind = svn.ra.check_path(self.ra, entrypath, revnum) | ||||
if kind == svn.core.svn_node_file: | ||||
if ent.copyfrom_path: | ||||
copyfrom_path = get_entry_from_path(ent.copyfrom_path) | ||||
if copyfrom_path: | ||||
self.ui.debug("Copied to %s from %s@%s\n" % (entry, copyfrom_path, ent.copyfrom_rev)) | ||||
# It's probably important for hg that the source | ||||
# exists in the revision's parent, not just the | ||||
# ent.copyfrom_rev | ||||
fromkind = svn.ra.check_path(self.ra, copyfrom_path, ent.copyfrom_rev) | ||||
if fromkind != 0: | ||||
copies[self.recode(entry)] = self.recode(copyfrom_path) | ||||
entries.append(self.recode(entry)) | ||||
elif kind == 0: # gone, but had better be a deleted *file* | ||||
self.ui.debug("gone from %s\n" % ent.copyfrom_rev) | ||||
# if a branch is created but entries are removed in the same | ||||
# changeset, get the right fromrev | ||||
if parents: | ||||
uuid, old_module, fromrev = self.revsplit(parents[0]) | ||||
else: | ||||
fromrev = revnum - 1 | ||||
# might always need to be revnum - 1 in these 3 lines? | ||||
old_module = self.modulemap.get(fromrev, self.module) | ||||
basepath = old_module + "/" + get_entry_from_path(path, module=self.module) | ||||
entrypath = old_module + "/" + get_entry_from_path(path, module=self.module) | ||||
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: | ||||
self.ui.debug("Found parent directory %s\n" % info[1]) | ||||
rc = info | ||||
return rc | ||||
self.ui.debug("base, entry %s %s\n" % (basepath, entrypath)) | ||||
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: | ||||
self.ui.debug("munge-o-matic\n") | ||||
self.ui.debug(entrypath + '\n') | ||||
self.ui.debug(entrypath[len(frompath):] + '\n') | ||||
entrypath = froment.copyfrom_path + entrypath[len(frompath):] | ||||
fromrev = froment.copyfrom_rev | ||||
self.ui.debug("Info: %s %s %s %s\n" % (frompath, froment, ent, entrypath)) | ||||
fromkind = svn.ra.check_path(self.ra, entrypath, fromrev) | ||||
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) | ||||
entrypath = get_entry_from_path("/" + child, module=old_module) | ||||
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: | ||||
self.ui.debug('unknown path in revision %d: %s\n' % \ | ||||
(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. | ||||
# 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. | ||||
children = self._find_children(path, revnum) | ||||
children.sort() | ||||
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) | ||||
entrypath = get_entry_from_path("/" + child, module=self.module) | ||||
# print child, self.module, entrypath | ||||
if entrypath: | ||||
# Need to filter out directories here... | ||||
kind = svn.ra.check_path(self.ra, entrypath, revnum) | ||||
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 | ||||
# Can do this with the copy command "hg copy" | ||||
# if ent.copyfrom_path: | ||||
# copyfrom_entry = get_entry_from_path(ent.copyfrom_path.decode(self.encoding), | ||||
# module=self.module) | ||||
# copyto_entry = entrypath | ||||
# | ||||
# print "copy directory", copyfrom_entry, 'to', copyto_entry | ||||
# | ||||
# copies.append((copyfrom_entry, copyto_entry)) | ||||
if ent.copyfrom_path: | ||||
copyfrom_path = ent.copyfrom_path.decode(self.encoding) | ||||
copyfrom_entry = get_entry_from_path(copyfrom_path, module=self.module) | ||||
if copyfrom_entry: | ||||
copyfrom[path] = ent | ||||
self.ui.debug("mark %s came from %s\n" % (path, copyfrom[path])) | ||||
# Good, /probably/ a regular copy. Really should check | ||||
# to see whether the parent revision actually contains | ||||
# the directory in question. | ||||
children = self._find_children(self.recode(copyfrom_path), ent.copyfrom_rev) | ||||
children.sort() | ||||
for child in children: | ||||
entrypath = get_entry_from_path("/" + child, module=self.module) | ||||
if entrypath: | ||||
entry = entrypath.decode(self.encoding) | ||||
# print "COPY COPY From", copyfrom_entry, entry | ||||
copyto_path = path + entry[len(copyfrom_entry):] | ||||
copyto_entry = get_entry_from_path(copyto_path, module=self.module) | ||||
# print "COPY", entry, "COPY To", copyto_entry | ||||
copies[self.recode(copyto_entry)] = self.recode(entry) | ||||
# copy from quux splort/quuxfile | ||||
return (entries, copies) | ||||
def _fetch_revisions(self, from_revnum = 0, to_revnum = 347): | ||||
|
r4940 | self.child_cset = None | ||
|
r4946 | def parselogentry(orig_paths, revnum, author, date, message): | ||
self.ui.debug("parsing revision %d (%d changes)\n" % | ||||
(revnum, len(orig_paths))) | ||||
|
r4940 | |||
|
r4765 | if revnum in self.modulemap: | ||
new_module = self.modulemap[revnum] | ||||
if new_module != self.module: | ||||
self.module = new_module | ||||
self.reparent(self.module) | ||||
|
r4810 | rev = self.revid(revnum) | ||
|
r4837 | # branch log might return entries for a parent we already have | ||
|
r4839 | if (rev in self.commits or | ||
(revnum < self.lastrevs.get(self.module, 0))): | ||||
|
r4837 | return | ||
|
r5120 | parents = [] | ||
|
r5119 | # check whether this revision is the start of a branch | ||
|
r5250 | if self.module in orig_paths: | ||
ent = orig_paths[self.module] | ||||
|
r5119 | if ent.copyfrom_path: | ||
# ent.copyfrom_rev may not be the actual last revision | ||||
prev = self.latest(ent.copyfrom_path, ent.copyfrom_rev) | ||||
self.modulemap[prev] = ent.copyfrom_path | ||||
parents = [self.revid(prev, ent.copyfrom_path)] | ||||
self.ui.note('found parent of branch %s at %d: %s\n' % \ | ||||
(self.module, prev, ent.copyfrom_path)) | ||||
else: | ||||
self.ui.debug("No copyfrom path, don't know what to do.\n") | ||||
|
r5120 | self.modulemap[revnum] = self.module # track backwards in time | ||
|
r5250 | orig_paths = orig_paths.items() | ||
orig_paths.sort() | ||||
|
r5120 | paths = [] | ||
# filter out unrelated paths | ||||
|
r4940 | for path, ent in orig_paths: | ||
|
r5120 | if not path.startswith(self.module): | ||
|
r4788 | self.ui.debug("boring@%s: %s\n" % (revnum, path)) | ||
continue | ||||
|
r5120 | paths.append((path, ent)) | ||
|
r4765 | |||
|
r5121 | self.paths[rev] = (paths, parents) | ||
|
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 | |||
|
r4788 | log = message and self.recode(message) | ||
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 | ||
if self.child_cset and not self.child_cset.parents: | ||||
|
r4788 | self.child_cset.parents = [rev] | ||
self.child_cset = cset | ||||
|
r4796 | |||
|
r4940 | self.ui.note('fetching revision log for "%s" from %d to %d\n' % | ||
|
r4797 | (self.module, from_revnum, to_revnum)) | ||
|
r4765 | |||
try: | ||||
|
r4946 | for entry in self.get_log([self.module], from_revnum, to_revnum): | ||
orig_paths, revnum, author, date, message = entry | ||||
if self.is_blacklisted(revnum): | ||||
self.ui.note('skipping blacklisted revision %d\n' % revnum) | ||||
continue | ||||
if orig_paths is None: | ||||
self.ui.debug('revision %d has no entries\n' % revnum) | ||||
continue | ||||
parselogentry(orig_paths, revnum, author, date, message) | ||||
|
r5140 | except SubversionException, (inst, num): | ||
|
r4765 | if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: | ||
|
r4957 | raise NoSuchRevision(branch=self, | ||
|
r4765 | revision="Revision number %d" % to_revnum) | ||
raise | ||||
def _getfile(self, file, rev): | ||||
io = StringIO() | ||||
# TODO: ra.get_file transmits the whole file instead of diffs. | ||||
mode = '' | ||||
try: | ||||
|
r4774 | revnum = self.revnum(rev) | ||
|
r4765 | if self.module != self.modulemap[revnum]: | ||
self.module = self.modulemap[revnum] | ||||
self.reparent(self.module) | ||||
info = svn.ra.get_file(self.ra, file, revnum, io) | ||||
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 | ||||
data = io.getvalue() | ||||
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() | ||
|
r5114 | rpath = '/'.join([self.base, path]).strip('/') | ||
|
r5117 | return ['%s/%s' % (path, x) for x in svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool).keys()] | ||