hg.py
1422 lines
| 45.3 KiB
| text/x-python
|
PythonLexer
/ mercurial / hg.py
|
r0 | # hg.py - repository classes for mercurial | ||
# | ||||
# Copyright 2005 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
# This software may be used and distributed according to the terms | ||||
# of the GNU General Public License, incorporated herein by reference. | ||||
|
r249 | import sys, struct, os | ||
|
r262 | from revlog import * | ||
from demandload import * | ||||
demandload(globals(), "re lock urllib urllib2 transaction time socket") | ||||
|
r372 | demandload(globals(), "tempfile httprangereader difflib") | ||
|
r0 | |||
|
r276 | def is_exec(f): | ||
return (os.stat(f).st_mode & 0100 != 0) | ||||
def set_exec(f, mode): | ||||
s = os.stat(f).st_mode | ||||
if (s & 0100 != 0) == mode: | ||||
return | ||||
|
r298 | if mode: | ||
|
r299 | # Turn on +x for every +r bit when making a file executable | ||
# and obey umask. | ||||
|
r298 | umask = os.umask(0) | ||
os.umask(umask) | ||||
os.chmod(f, s | (s & 0444) >> 2 & ~umask) | ||||
else: | ||||
os.chmod(f, s & 0666) | ||||
|
r276 | |||
|
r0 | class filelog(revlog): | ||
def __init__(self, opener, path): | ||||
|
r144 | revlog.__init__(self, opener, | ||
os.path.join("data", path + ".i"), | ||||
os.path.join("data", path + ".d")) | ||||
|
r0 | |||
def read(self, node): | ||||
|
r360 | t = self.revision(node) | ||
if t[:2] != '\1\n': | ||||
return t | ||||
s = t.find('\1\n', 2) | ||||
return t[s+2:] | ||||
def readmeta(self, node): | ||||
t = self.revision(node) | ||||
if t[:2] != '\1\n': | ||||
return t | ||||
s = t.find('\1\n', 2) | ||||
mt = t[2:s] | ||||
for l in mt.splitlines(): | ||||
k, v = l.split(": ", 1) | ||||
m[k] = v | ||||
return m | ||||
def add(self, text, meta, transaction, link, p1=None, p2=None): | ||||
if meta or text[:2] == '\1\n': | ||||
mt = "" | ||||
if meta: | ||||
mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ] | ||||
text = "\1\n" + "".join(mt) + "\1\n" + text | ||||
|
r0 | return self.addrevision(text, transaction, link, p1, p2) | ||
|
r79 | def annotate(self, node): | ||
|
r199 | |||
def decorate(text, rev): | ||||
return [(rev, l) for l in text.splitlines(1)] | ||||
def strip(annotation): | ||||
return [e[1] for e in annotation] | ||||
def pair(parent, child): | ||||
|
r109 | new = [] | ||
|
r262 | sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) | ||
|
r79 | for o, m, n, s, t in sm.get_opcodes(): | ||
|
r109 | if o == 'equal': | ||
|
r199 | new += parent[m:n] | ||
|
r109 | else: | ||
|
r199 | new += child[s:t] | ||
return new | ||||
|
r200 | # find all ancestors | ||
|
r216 | needed = {node:1} | ||
|
r199 | visit = [node] | ||
while visit: | ||||
n = visit.pop(0) | ||||
for p in self.parents(n): | ||||
if p not in needed: | ||||
needed[p] = 1 | ||||
visit.append(p) | ||||
|
r200 | else: | ||
# count how many times we'll use this | ||||
needed[p] += 1 | ||||
|
r199 | |||
|
r200 | # sort by revision which is a topological order | ||
|
r199 | visit = needed.keys() | ||
visit = [ (self.rev(n), n) for n in visit ] | ||||
visit.sort() | ||||
visit = [ p[1] for p in visit ] | ||||
hist = {} | ||||
for n in visit: | ||||
curr = decorate(self.read(n), self.linkrev(n)) | ||||
for p in self.parents(n): | ||||
if p != nullid: | ||||
curr = pair(hist[p], curr) | ||||
|
r200 | # trim the history of unneeded revs | ||
needed[p] -= 1 | ||||
if not needed[p]: | ||||
del hist[p] | ||||
|
r199 | hist[n] = curr | ||
return hist[n] | ||||
|
r79 | |||
|
r0 | class manifest(revlog): | ||
def __init__(self, opener): | ||||
self.mapcache = None | ||||
self.listcache = None | ||||
self.addlist = None | ||||
revlog.__init__(self, opener, "00manifest.i", "00manifest.d") | ||||
def read(self, node): | ||||
|
r313 | if node == nullid: return {} # don't upset local cache | ||
|
r0 | if self.mapcache and self.mapcache[0] == node: | ||
|
r90 | return self.mapcache[1].copy() | ||
|
r0 | text = self.revision(node) | ||
map = {} | ||||
|
r276 | flag = {} | ||
|
r25 | self.listcache = (text, text.splitlines(1)) | ||
for l in self.listcache[1]: | ||||
|
r0 | (f, n) = l.split('\0') | ||
map[f] = bin(n[:40]) | ||||
|
r276 | flag[f] = (n[40:-1] == "x") | ||
self.mapcache = (node, map, flag) | ||||
|
r0 | return map | ||
|
r276 | def readflags(self, node): | ||
|
r313 | if node == nullid: return {} # don't upset local cache | ||
|
r358 | if not self.mapcache or self.mapcache[0] != node: | ||
|
r276 | self.read(node) | ||
return self.mapcache[2] | ||||
|
r0 | def diff(self, a, b): | ||
# this is sneaky, as we're not actually using a and b | ||||
|
r140 | if self.listcache and self.addlist and self.listcache[0] == a: | ||
|
r98 | d = mdiff.diff(self.listcache[1], self.addlist, 1) | ||
if mdiff.patch(a, d) != b: | ||||
sys.stderr.write("*** sortdiff failed, falling back ***\n") | ||||
return mdiff.textdiff(a, b) | ||||
return d | ||||
|
r0 | else: | ||
|
r44 | return mdiff.textdiff(a, b) | ||
|
r0 | |||
|
r276 | def add(self, map, flags, transaction, link, p1=None, p2=None): | ||
|
r0 | files = map.keys() | ||
files.sort() | ||||
|
r276 | self.addlist = ["%s\000%s%s\n" % | ||
(f, hex(map[f]), flags[f] and "x" or '') | ||||
for f in files] | ||||
|
r0 | text = "".join(self.addlist) | ||
n = self.addrevision(text, transaction, link, p1, p2) | ||||
|
r302 | self.mapcache = (n, map, flags) | ||
|
r25 | self.listcache = (text, self.addlist) | ||
|
r140 | self.addlist = None | ||
|
r0 | |||
return n | ||||
class changelog(revlog): | ||||
def __init__(self, opener): | ||||
revlog.__init__(self, opener, "00changelog.i", "00changelog.d") | ||||
def extract(self, text): | ||||
|
r37 | if not text: | ||
|
r40 | return (nullid, "", "0", [], "") | ||
|
r0 | last = text.index("\n\n") | ||
desc = text[last + 2:] | ||||
l = text[:last].splitlines() | ||||
manifest = bin(l[0]) | ||||
user = l[1] | ||||
date = l[2] | ||||
files = l[3:] | ||||
return (manifest, user, date, files, desc) | ||||
def read(self, node): | ||||
return self.extract(self.revision(node)) | ||||
|
r203 | def add(self, manifest, list, desc, transaction, p1=None, p2=None, | ||
user=None, date=None): | ||||
user = (user or | ||||
os.environ.get("HGUSER") or | ||||
|
r55 | os.environ.get("EMAIL") or | ||
os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) | ||||
|
r203 | date = date or "%d %d" % (time.time(), time.timezone) | ||
|
r0 | list.sort() | ||
l = [hex(manifest), user, date] + list + ["", desc] | ||||
text = "\n".join(l) | ||||
return self.addrevision(text, transaction, self.count(), p1, p2) | ||||
|
r220 | class dirstate: | ||
|
r244 | def __init__(self, opener, ui, root): | ||
|
r0 | self.opener = opener | ||
|
r244 | self.root = root | ||
|
r0 | self.dirty = 0 | ||
|
r20 | self.ui = ui | ||
|
r0 | self.map = None | ||
|
r227 | self.pl = None | ||
|
r363 | self.copies = {} | ||
|
r220 | |||
|
r0 | def __del__(self): | ||
|
r220 | if self.dirty: | ||
self.write() | ||||
|
r0 | def __getitem__(self, key): | ||
try: | ||||
return self.map[key] | ||||
except TypeError: | ||||
self.read() | ||||
return self[key] | ||||
|
r220 | |||
def __contains__(self, key): | ||||
if not self.map: self.read() | ||||
return key in self.map | ||||
|
r227 | def parents(self): | ||
if not self.pl: | ||||
self.read() | ||||
return self.pl | ||||
def setparents(self, p1, p2 = nullid): | ||||
self.dirty = 1 | ||||
self.pl = p1, p2 | ||||
|
r220 | def state(self, key): | ||
try: | ||||
return self[key][0] | ||||
except KeyError: | ||||
return "?" | ||||
|
r0 | def read(self): | ||
if self.map is not None: return self.map | ||||
self.map = {} | ||||
|
r227 | self.pl = [nullid, nullid] | ||
|
r0 | try: | ||
|
r220 | st = self.opener("dirstate").read() | ||
|
r311 | if not st: return | ||
|
r0 | except: return | ||
|
r227 | self.pl = [st[:20], st[20: 40]] | ||
pos = 40 | ||||
|
r0 | while pos < len(st): | ||
|
r220 | e = struct.unpack(">cllll", st[pos:pos+17]) | ||
l = e[4] | ||||
pos += 17 | ||||
|
r0 | f = st[pos:pos + l] | ||
|
r363 | if '\0' in f: | ||
f, c = f.split('\0') | ||||
self.copies[f] = c | ||||
|
r220 | self.map[f] = e[:4] | ||
|
r0 | pos += l | ||
|
r363 | |||
def copy(self, source, dest): | ||||
self.read() | ||||
self.dirty = 1 | ||||
self.copies[dest] = source | ||||
def copied(self, file): | ||||
return self.copies.get(file, None) | ||||
|
r0 | |||
|
r220 | def update(self, files, state): | ||
''' current states: | ||||
n normal | ||||
|
r231 | m needs merging | ||
|
r220 | r marked for removal | ||
a marked for addition''' | ||||
|
r0 | if not files: return | ||
self.read() | ||||
self.dirty = 1 | ||||
for f in files: | ||||
|
r220 | if state == "r": | ||
self.map[f] = ('r', 0, 0, 0) | ||||
else: | ||||
|
r253 | s = os.stat(os.path.join(self.root, f)) | ||
self.map[f] = (state, s.st_mode, s.st_size, s.st_mtime) | ||||
|
r0 | |||
|
r220 | def forget(self, files): | ||
|
r0 | if not files: return | ||
self.read() | ||||
self.dirty = 1 | ||||
for f in files: | ||||
|
r20 | try: | ||
del self.map[f] | ||||
except KeyError: | ||||
|
r220 | self.ui.warn("not in dirstate: %s!\n" % f) | ||
|
r20 | pass | ||
|
r0 | |||
def clear(self): | ||||
self.map = {} | ||||
self.dirty = 1 | ||||
def write(self): | ||||
|
r220 | st = self.opener("dirstate", "w") | ||
|
r227 | st.write("".join(self.pl)) | ||
|
r0 | for f, e in self.map.items(): | ||
|
r363 | c = self.copied(f) | ||
if c: | ||||
f = f + "\0" + c | ||||
|
r220 | e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f)) | ||
|
r0 | st.write(e + f) | ||
self.dirty = 0 | ||||
|
r363 | def dup(self): | ||
|
r0 | self.read() | ||
return self.map.copy() | ||||
# used to avoid circular references so destructors work | ||||
def opener(base): | ||||
p = base | ||||
def o(path, mode="r"): | ||||
|
r15 | if p[:7] == "http://": | ||
f = os.path.join(p, urllib.quote(path)) | ||||
|
r372 | return httprangereader.httprangereader(f) | ||
|
r15 | |||
|
r0 | f = os.path.join(p, path) | ||
|
r292 | mode += "b" # for that other OS | ||
if mode[0] != "r": | ||||
|
r110 | try: | ||
s = os.stat(f) | ||||
except OSError: | ||||
d = os.path.dirname(f) | ||||
if not os.path.isdir(d): | ||||
os.makedirs(d) | ||||
else: | ||||
if s.st_nlink > 1: | ||||
file(f + ".tmp", "w").write(file(f).read()) | ||||
os.rename(f+".tmp", f) | ||||
|
r0 | |||
return file(f, mode) | ||||
return o | ||||
|
r60 | class localrepository: | ||
|
r0 | def __init__(self, ui, path=None, create=0): | ||
self.remote = 0 | ||||
if path and path[:7] == "http://": | ||||
self.remote = 1 | ||||
self.path = path | ||||
else: | ||||
if not path: | ||||
p = os.getcwd() | ||||
while not os.path.isdir(os.path.join(p, ".hg")): | ||||
p = os.path.dirname(p) | ||||
if p == "/": raise "No repo found" | ||||
path = p | ||||
self.path = os.path.join(path, ".hg") | ||||
self.root = path | ||||
self.ui = ui | ||||
if create: | ||||
os.mkdir(self.path) | ||||
os.mkdir(self.join("data")) | ||||
self.opener = opener(self.path) | ||||
|
r291 | self.wopener = opener(self.root) | ||
|
r0 | self.manifest = manifest(self.opener) | ||
self.changelog = changelog(self.opener) | ||||
self.ignorelist = None | ||||
|
r343 | self.tagscache = None | ||
self.nodetagscache = None | ||||
|
r0 | |||
if not self.remote: | ||||
|
r244 | self.dirstate = dirstate(self.opener, ui, self.root) | ||
|
r337 | try: | ||
self.ui.readconfig(self.opener("hgrc")) | ||||
except IOError: pass | ||||
|
r0 | |||
def ignore(self, f): | ||||
if self.ignorelist is None: | ||||
self.ignorelist = [] | ||||
try: | ||||
|
r291 | l = self.wfile(".hgignore") | ||
|
r0 | for pat in l: | ||
|
r9 | if pat != "\n": | ||
self.ignorelist.append(re.compile(pat[:-1])) | ||||
|
r0 | except IOError: pass | ||
for pat in self.ignorelist: | ||||
if pat.search(f): return True | ||||
return False | ||||
|
r343 | def tags(self): | ||
'''return a mapping of tag to node''' | ||||
if not self.tagscache: | ||||
self.tagscache = {} | ||||
|
r67 | try: | ||
|
r254 | # read each head of the tags file, ending with the tip | ||
# and add each tag found to the map, with "newer" ones | ||||
# taking precedence | ||||
|
r67 | fl = self.file(".hgtags") | ||
|
r254 | h = fl.heads() | ||
h.reverse() | ||||
for r in h: | ||||
for l in fl.revision(r).splitlines(): | ||||
if l: | ||||
|
r385 | n, k = l.split(" ", 1) | ||
self.tagscache[k.strip()] = bin(n) | ||||
|
r67 | except KeyError: pass | ||
|
r343 | self.tagscache['tip'] = self.changelog.tip() | ||
return self.tagscache | ||||
def tagslist(self): | ||||
'''return a list of tags ordered by revision''' | ||||
l = [] | ||||
for t,n in self.tags().items(): | ||||
try: | ||||
r = self.changelog.rev(n) | ||||
except: | ||||
r = -2 # sort to the beginning of the list if unknown | ||||
l.append((r,t,n)) | ||||
l.sort() | ||||
return [(t,n) for r,t,n in l] | ||||
def nodetags(self, node): | ||||
'''return the tags associated with a node''' | ||||
if not self.nodetagscache: | ||||
self.nodetagscache = {} | ||||
for t,n in self.tags().items(): | ||||
self.nodetagscache.setdefault(n,[]).append(t) | ||||
return self.nodetagscache.get(node, []) | ||||
def lookup(self, key): | ||||
|
r67 | try: | ||
|
r343 | return self.tags()[key] | ||
|
r67 | except KeyError: | ||
return self.changelog.lookup(key) | ||||
|
r0 | def join(self, f): | ||
return os.path.join(self.path, f) | ||||
|
r244 | def wjoin(self, f): | ||
return os.path.join(self.root, f) | ||||
|
r0 | def file(self, f): | ||
|
r192 | if f[0] == '/': f = f[1:] | ||
|
r144 | return filelog(self.opener, f) | ||
|
r0 | |||
|
r291 | def wfile(self, f, mode='r'): | ||
return self.wopener(f, mode) | ||||
|
r0 | def transaction(self): | ||
|
r251 | # save dirstate for undo | ||
|
r263 | try: | ||
ds = self.opener("dirstate").read() | ||||
except IOError: | ||||
ds = "" | ||||
|
r251 | self.opener("undo.dirstate", "w").write(ds) | ||
|
r262 | |||
return transaction.transaction(self.opener, self.join("journal"), | ||||
self.join("undo")) | ||||
|
r0 | |||
|
r210 | def recover(self): | ||
|
r225 | lock = self.lock() | ||
|
r210 | if os.path.exists(self.join("recover")): | ||
self.ui.status("attempting to rollback interrupted transaction\n") | ||||
|
r262 | return transaction.rollback(self.opener, self.join("recover")) | ||
|
r210 | else: | ||
self.ui.warn("no interrupted transaction available\n") | ||||
def undo(self): | ||||
|
r225 | lock = self.lock() | ||
|
r210 | if os.path.exists(self.join("undo")): | ||
self.ui.status("attempting to rollback last transaction\n") | ||||
|
r262 | transaction.rollback(self.opener, self.join("undo")) | ||
|
r251 | self.dirstate = None | ||
os.rename(self.join("undo.dirstate"), self.join("dirstate")) | ||||
self.dirstate = dirstate(self.opener, self.ui, self.root) | ||||
|
r163 | else: | ||
|
r210 | self.ui.warn("no undo information available\n") | ||
|
r162 | |||
|
r161 | def lock(self, wait = 1): | ||
try: | ||||
return lock.lock(self.join("lock"), 0) | ||||
except lock.LockHeld, inst: | ||||
if wait: | ||||
self.ui.warn("waiting for lock held by %s\n" % inst.args[0]) | ||||
return lock.lock(self.join("lock"), wait) | ||||
raise inst | ||||
|
r203 | def rawcommit(self, files, text, user, date, p1=None, p2=None): | ||
|
r228 | p1 = p1 or self.dirstate.parents()[0] or nullid | ||
p2 = p2 or self.dirstate.parents()[1] or nullid | ||||
|
r302 | c1 = self.changelog.read(p1) | ||
c2 = self.changelog.read(p2) | ||||
m1 = self.manifest.read(c1[0]) | ||||
mf1 = self.manifest.readflags(c1[0]) | ||||
m2 = self.manifest.read(c2[0]) | ||||
|
r203 | tr = self.transaction() | ||
|
r302 | mm = m1.copy() | ||
mfm = mf1.copy() | ||||
|
r203 | linkrev = self.changelog.count() | ||
|
r314 | self.dirstate.setparents(p1, p2) | ||
|
r203 | for f in files: | ||
try: | ||||
|
r302 | t = self.wfile(f).read() | ||
tm = is_exec(self.wjoin(f)) | ||||
r = self.file(f) | ||||
mfm[f] = tm | ||||
|
r360 | mm[f] = r.add(t, {}, tr, linkrev, | ||
|
r302 | m1.get(f, nullid), m2.get(f, nullid)) | ||
|
r314 | self.dirstate.update([f], "n") | ||
|
r203 | except IOError: | ||
|
r314 | try: | ||
del mm[f] | ||||
del mfm[f] | ||||
self.dirstate.forget([f]) | ||||
except: | ||||
# deleted from p2? | ||||
pass | ||||
|
r203 | |||
|
r302 | mnode = self.manifest.add(mm, mfm, tr, linkrev, c1[0], c2[0]) | ||
n = self.changelog.add(mnode, files, text, tr, p1, p2, user, date) | ||||
|
r203 | tr.close() | ||
|
r317 | def commit(self, files = None, text = "", user = None, date = None): | ||
|
r220 | commit = [] | ||
remove = [] | ||||
if files: | ||||
for f in files: | ||||
s = self.dirstate.state(f) | ||||
|
r244 | if s in 'nmai': | ||
|
r220 | commit.append(f) | ||
elif s == 'r': | ||||
remove.append(f) | ||||
else: | ||||
|
r244 | self.ui.warn("%s not tracked!\n" % f) | ||
|
r220 | else: | ||
|
r230 | (c, a, d, u) = self.diffdir(self.root) | ||
|
r220 | commit = c + a | ||
remove = d | ||||
|
r0 | |||
|
r220 | if not commit and not remove: | ||
|
r151 | self.ui.status("nothing changed\n") | ||
return | ||||
|
r229 | p1, p2 = self.dirstate.parents() | ||
c1 = self.changelog.read(p1) | ||||
c2 = self.changelog.read(p2) | ||||
m1 = self.manifest.read(c1[0]) | ||||
|
r276 | mf1 = self.manifest.readflags(c1[0]) | ||
|
r229 | m2 = self.manifest.read(c2[0]) | ||
|
r225 | lock = self.lock() | ||
|
r151 | tr = self.transaction() | ||
|
r0 | # check in files | ||
new = {} | ||||
linkrev = self.changelog.count() | ||||
|
r220 | commit.sort() | ||
for f in commit: | ||||
|
r83 | self.ui.note(f + "\n") | ||
|
r0 | try: | ||
|
r276 | fp = self.wjoin(f) | ||
mf1[f] = is_exec(fp) | ||||
t = file(fp).read() | ||||
|
r0 | except IOError: | ||
|
r220 | self.warn("trouble committing %s!\n" % f) | ||
raise | ||||
|
r363 | meta = {} | ||
cp = self.dirstate.copied(f) | ||||
if cp: | ||||
meta["copy"] = cp | ||||
meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) | ||||
self.ui.debug(" %s: copy %s:%s\n" % (f, cp, meta["copyrev"])) | ||||
|
r0 | r = self.file(f) | ||
|
r229 | fp1 = m1.get(f, nullid) | ||
fp2 = m2.get(f, nullid) | ||||
|
r363 | new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) | ||
|
r0 | |||
# update manifest | ||||
|
r229 | m1.update(new) | ||
for f in remove: del m1[f] | ||||
|
r276 | mn = self.manifest.add(m1, mf1, tr, linkrev, c1[0], c2[0]) | ||
|
r0 | |||
# add changeset | ||||
new = new.keys() | ||||
new.sort() | ||||
|
r288 | if not text: | ||
edittext = "\n" + "HG: manifest hash %s\n" % hex(mn) | ||||
edittext += "".join(["HG: changed %s\n" % f for f in new]) | ||||
edittext += "".join(["HG: removed %s\n" % f for f in remove]) | ||||
edittext = self.ui.edit(edittext) | ||||
if not edittext.rstrip(): | ||||
return 1 | ||||
text = edittext | ||||
|
r0 | |||
|
r317 | n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) | ||
|
r0 | tr.close() | ||
|
r229 | self.dirstate.setparents(n) | ||
|
r220 | self.dirstate.update(new, "n") | ||
self.dirstate.forget(remove) | ||||
|
r0 | |||
|
r230 | def diffdir(self, path, changeset = None): | ||
|
r0 | changed = [] | ||
|
r220 | added = [] | ||
unknown = [] | ||||
|
r4 | mf = {} | ||
|
r0 | |||
|
r29 | if changeset: | ||
change = self.changelog.read(changeset) | ||||
|
r4 | mf = self.manifest.read(change[0]) | ||
|
r230 | dc = dict.fromkeys(mf) | ||
else: | ||||
changeset = self.dirstate.parents()[0] | ||||
change = self.changelog.read(changeset) | ||||
mf = self.manifest.read(change[0]) | ||||
|
r363 | dc = self.dirstate.dup() | ||
|
r29 | |||
def fcmp(fn): | ||||
|
r291 | t1 = self.wfile(fn).read() | ||
|
r29 | t2 = self.file(fn).revision(mf[fn]) | ||
return cmp(t1, t2) | ||||
|
r312 | for dir, subdirs, files in os.walk(path): | ||
|
r0 | d = dir[len(self.root)+1:] | ||
if ".hg" in subdirs: subdirs.remove(".hg") | ||||
for f in files: | ||||
fn = os.path.join(d, f) | ||||
|
r64 | try: s = os.stat(os.path.join(self.root, fn)) | ||
|
r0 | except: continue | ||
if fn in dc: | ||||
c = dc[fn] | ||||
del dc[fn] | ||||
|
r220 | if not c: | ||
|
r29 | if fcmp(fn): | ||
changed.append(fn) | ||||
|
r231 | elif c[0] == 'm': | ||
changed.append(fn) | ||||
|
r220 | elif c[0] == 'a': | ||
added.append(fn) | ||||
elif c[0] == 'r': | ||||
unknown.append(fn) | ||||
|
r276 | elif c[2] != s.st_size or (c[1] ^ s.st_mode) & 0100: | ||
|
r0 | changed.append(fn) | ||
|
r220 | elif c[1] != s.st_mode or c[3] != s.st_mtime: | ||
|
r29 | if fcmp(fn): | ||
|
r0 | changed.append(fn) | ||
else: | ||||
if self.ignore(fn): continue | ||||
|
r220 | unknown.append(fn) | ||
|
r0 | |||
deleted = dc.keys() | ||||
deleted.sort() | ||||
|
r220 | return (changed, added, deleted, unknown) | ||
|
r0 | |||
|
r32 | def diffrevs(self, node1, node2): | ||
|
r33 | changed, added = [], [] | ||
|
r32 | |||
change = self.changelog.read(node1) | ||||
mf1 = self.manifest.read(change[0]) | ||||
|
r33 | change = self.changelog.read(node2) | ||
|
r32 | mf2 = self.manifest.read(change[0]) | ||
for fn in mf2: | ||||
if mf1.has_key(fn): | ||||
if mf1[fn] != mf2[fn]: | ||||
changed.append(fn) | ||||
del mf1[fn] | ||||
else: | ||||
added.append(fn) | ||||
deleted = mf1.keys() | ||||
deleted.sort() | ||||
return (changed, added, deleted) | ||||
|
r0 | def add(self, list): | ||
|
r220 | for f in list: | ||
|
r244 | p = self.wjoin(f) | ||
|
r220 | if not os.path.isfile(p): | ||
self.ui.warn("%s does not exist!\n" % f) | ||||
elif self.dirstate.state(f) == 'n': | ||||
self.ui.warn("%s already tracked!\n" % f) | ||||
else: | ||||
self.dirstate.update([f], "a") | ||||
def forget(self, list): | ||||
for f in list: | ||||
if self.dirstate.state(f) not in 'ai': | ||||
self.ui.warn("%s not added!\n" % f) | ||||
else: | ||||
self.dirstate.forget([f]) | ||||
|
r0 | |||
def remove(self, list): | ||||
for f in list: | ||||
|
r244 | p = self.wjoin(f) | ||
|
r220 | if os.path.isfile(p): | ||
self.ui.warn("%s still exists!\n" % f) | ||||
elif f not in self.dirstate: | ||||
self.ui.warn("%s not tracked!\n" % f) | ||||
else: | ||||
self.dirstate.update([f], "r") | ||||
|
r0 | |||
|
r363 | def copy(self, source, dest): | ||
p = self.wjoin(dest) | ||||
if not os.path.isfile(dest): | ||||
self.ui.warn("%s does not exist!\n" % dest) | ||||
else: | ||||
if self.dirstate.state(dest) == '?': | ||||
self.dirstate.update([dest], "a") | ||||
self.dirstate.copy(source, dest) | ||||
|
r222 | def heads(self): | ||
return self.changelog.heads() | ||||
|
r56 | def branches(self, nodes): | ||
if not nodes: nodes = [self.changelog.tip()] | ||||
b = [] | ||||
for n in nodes: | ||||
t = n | ||||
while n: | ||||
p = self.changelog.parents(n) | ||||
if p[1] != nullid or p[0] == nullid: | ||||
b.append((t, n, p[0], p[1])) | ||||
break | ||||
n = p[0] | ||||
return b | ||||
def between(self, pairs): | ||||
r = [] | ||||
for top, bottom in pairs: | ||||
n, l, i = top, [], 0 | ||||
f = 1 | ||||
while n != bottom: | ||||
p = self.changelog.parents(n)[0] | ||||
if i == f: | ||||
l.append(n) | ||||
f = f * 2 | ||||
n = p | ||||
i += 1 | ||||
r.append(l) | ||||
return r | ||||
def newer(self, nodes): | ||||
m = {} | ||||
nl = [] | ||||
|
r94 | pm = {} | ||
|
r56 | cl = self.changelog | ||
t = l = cl.count() | ||||
|
r94 | |||
# find the lowest numbered node | ||||
|
r56 | for n in nodes: | ||
l = min(l, cl.rev(n)) | ||||
|
r94 | m[n] = 1 | ||
|
r46 | |||
|
r56 | for i in xrange(l, t): | ||
n = cl.node(i) | ||||
|
r94 | if n in m: # explicitly listed | ||
pm[n] = 1 | ||||
nl.append(n) | ||||
continue | ||||
|
r56 | for p in cl.parents(n): | ||
|
r94 | if p in pm: # parent listed | ||
pm[n] = 1 | ||||
|
r56 | nl.append(n) | ||
|
r94 | break | ||
|
r56 | |||
return nl | ||||
def getchangegroup(self, remote): | ||||
|
r65 | m = self.changelog.nodemap | ||
|
r56 | search = [] | ||
fetch = [] | ||||
|
r148 | seen = {} | ||
seenbranch = {} | ||||
|
r192 | |||
|
r190 | # if we have an empty repo, fetch everything | ||
if self.changelog.tip() == nullid: | ||||
|
r222 | self.ui.status("requesting all changes\n") | ||
|
r190 | return remote.changegroup([nullid]) | ||
# otherwise, assume we're closer to the tip than the root | ||||
|
r222 | self.ui.status("searching for changes\n") | ||
heads = remote.heads() | ||||
unknown = [] | ||||
for h in heads: | ||||
if h not in m: | ||||
unknown.append(h) | ||||
|
r46 | |||
|
r222 | if not unknown: | ||
|
r192 | self.ui.status("nothing to do!\n") | ||
|
r60 | return None | ||
|
r324 | |||
rep = {} | ||||
reqcnt = 0 | ||||
|
r222 | unknown = remote.branches(unknown) | ||
|
r56 | while unknown: | ||
|
r324 | r = [] | ||
while unknown: | ||||
n = unknown.pop(0) | ||||
if n[0] in seen: | ||||
continue | ||||
|
r148 | |||
|
r324 | self.ui.debug("examining %s:%s\n" % (short(n[0]), short(n[1]))) | ||
if n[0] == nullid: | ||||
break | ||||
|
r328 | if n in seenbranch: | ||
|
r324 | self.ui.debug("branch already found\n") | ||
continue | ||||
if n[1] and n[1] in m: # do we know the base? | ||||
self.ui.debug("found incomplete branch %s:%s\n" | ||||
% (short(n[0]), short(n[1]))) | ||||
search.append(n) # schedule branch range for scanning | ||||
|
r328 | seenbranch[n] = 1 | ||
|
r324 | else: | ||
if n[1] not in seen and n[1] not in fetch: | ||||
if n[2] in m and n[3] in m: | ||||
self.ui.debug("found new changeset %s\n" % | ||||
short(n[1])) | ||||
fetch.append(n[1]) # earliest unknown | ||||
continue | ||||
for a in n[2:4]: | ||||
if a not in rep: | ||||
r.append(a) | ||||
rep[a] = 1 | ||||
|
r328 | seen[n[0]] = 1 | ||
|
r324 | if r: | ||
reqcnt += 1 | ||||
self.ui.debug("request %d: %s\n" % | ||||
(reqcnt, " ".join(map(short, r)))) | ||||
for p in range(0, len(r), 10): | ||||
for b in remote.branches(r[p:p+10]): | ||||
|
r148 | self.ui.debug("received %s:%s\n" % | ||
(short(b[0]), short(b[1]))) | ||||
if b[0] not in m and b[0] not in seen: | ||||
unknown.append(b) | ||||
|
r56 | |||
while search: | ||||
n = search.pop(0) | ||||
|
r324 | reqcnt += 1 | ||
|
r56 | l = remote.between([(n[0], n[1])])[0] | ||
|
r328 | l.append(n[1]) | ||
|
r56 | p = n[0] | ||
f = 1 | ||||
|
r328 | for i in l: | ||
self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) | ||||
|
r65 | if i in m: | ||
|
r85 | if f <= 2: | ||
|
r83 | self.ui.debug("found new branch changeset %s\n" % | ||
short(p)) | ||||
|
r56 | fetch.append(p) | ||
else: | ||||
|
r83 | self.ui.debug("narrowed branch search to %s:%s\n" | ||
% (short(p), short(i))) | ||||
|
r56 | search.append((p, i)) | ||
|
r65 | break | ||
|
r56 | p, f = i, f * 2 | ||
|
r65 | for f in fetch: | ||
if f in m: | ||||
|
r83 | raise "already have", short(f[:4]) | ||
|
r94 | self.ui.note("adding new changesets starting at " + | ||
|
r83 | " ".join([short(f) for f in fetch]) + "\n") | ||
|
r65 | |||
|
r324 | self.ui.debug("%d total queries\n" % reqcnt) | ||
|
r56 | return remote.changegroup(fetch) | ||
def changegroup(self, basenodes): | ||||
nodes = self.newer(basenodes) | ||||
|
r46 | # construct the link map | ||
linkmap = {} | ||||
for n in nodes: | ||||
linkmap[self.changelog.rev(n)] = n | ||||
# construct a list of all changed files | ||||
changed = {} | ||||
for n in nodes: | ||||
c = self.changelog.read(n) | ||||
for f in c[3]: | ||||
changed[f] = 1 | ||||
changed = changed.keys() | ||||
changed.sort() | ||||
# the changegroup is changesets + manifests + all file revs | ||||
revs = [ self.changelog.rev(n) for n in nodes ] | ||||
|
r192 | for y in self.changelog.group(linkmap): yield y | ||
for y in self.manifest.group(linkmap): yield y | ||||
|
r46 | for f in changed: | ||
|
r192 | yield struct.pack(">l", len(f) + 4) + f | ||
|
r46 | g = self.file(f).group(linkmap) | ||
|
r192 | for y in g: | ||
yield y | ||||
|
r46 | |||
|
r65 | def addchangegroup(self, generator): | ||
|
r222 | |||
class genread: | ||||
def __init__(self, generator): | ||||
self.g = generator | ||||
self.buf = "" | ||||
def read(self, l): | ||||
while l > len(self.buf): | ||||
try: | ||||
self.buf += self.g.next() | ||||
except StopIteration: | ||||
break | ||||
d, self.buf = self.buf[:l], self.buf[l:] | ||||
return d | ||||
def getchunk(): | ||||
d = source.read(4) | ||||
if not d: return "" | ||||
l = struct.unpack(">l", d)[0] | ||||
if l <= 4: return "" | ||||
return source.read(l - 4) | ||||
def getgroup(): | ||||
while 1: | ||||
c = getchunk() | ||||
if not c: break | ||||
yield c | ||||
def csmap(x): | ||||
self.ui.debug("add changeset %s\n" % short(x)) | ||||
return self.changelog.count() | ||||
def revmap(x): | ||||
return self.changelog.rev(x) | ||||
if not generator: return | ||||
changesets = files = revisions = 0 | ||||
|
r225 | |||
|
r222 | source = genread(generator) | ||
|
r225 | lock = self.lock() | ||
|
r222 | tr = self.transaction() | ||
# pull off the changeset group | ||||
self.ui.status("adding changesets\n") | ||||
co = self.changelog.tip() | ||||
|
r224 | cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique | ||
|
r222 | changesets = self.changelog.rev(cn) - self.changelog.rev(co) | ||
# pull off the manifest group | ||||
self.ui.status("adding manifests\n") | ||||
mm = self.manifest.tip() | ||||
mo = self.manifest.addgroup(getgroup(), revmap, tr) | ||||
# process the files | ||||
self.ui.status("adding file revisions\n") | ||||
while 1: | ||||
f = getchunk() | ||||
if not f: break | ||||
self.ui.debug("adding %s revisions\n" % f) | ||||
fl = self.file(f) | ||||
o = fl.tip() | ||||
n = fl.addgroup(getgroup(), revmap, tr) | ||||
revisions += fl.rev(n) - fl.rev(o) | ||||
files += 1 | ||||
self.ui.status(("modified %d files, added %d changesets" + | ||||
" and %d new revisions\n") | ||||
% (files, changesets, revisions)) | ||||
tr.close() | ||||
return | ||||
|
r275 | def update(self, node, allow=False, force=False): | ||
|
r232 | pl = self.dirstate.parents() | ||
|
r275 | if not force and pl[1] != nullid: | ||
|
r254 | self.ui.warn("aborting: outstanding uncommitted merges\n") | ||
|
r46 | return | ||
|
r232 | p1, p2 = pl[0], node | ||
|
r305 | pa = self.changelog.ancestor(p1, p2) | ||
|
r232 | m1n = self.changelog.read(p1)[0] | ||
m2n = self.changelog.read(p2)[0] | ||||
man = self.manifest.ancestor(m1n, m2n) | ||||
m1 = self.manifest.read(m1n) | ||||
|
r276 | mf1 = self.manifest.readflags(m1n) | ||
|
r232 | m2 = self.manifest.read(m2n) | ||
|
r276 | mf2 = self.manifest.readflags(m2n) | ||
|
r232 | ma = self.manifest.read(man) | ||
|
r276 | mfa = self.manifest.readflags(m2n) | ||
|
r232 | |||
(c, a, d, u) = self.diffdir(self.root) | ||||
# resolve the manifest to determine which files | ||||
# we care about merging | ||||
|
r254 | self.ui.note("resolving manifests\n") | ||
|
r232 | self.ui.debug(" ancestor %s local %s remote %s\n" % | ||
(short(man), short(m1n), short(m2n))) | ||||
merge = {} | ||||
get = {} | ||||
remove = [] | ||||
|
r305 | mark = {} | ||
|
r46 | |||
|
r232 | # construct a working dir manifest | ||
mw = m1.copy() | ||||
|
r276 | mfw = mf1.copy() | ||
|
r254 | for f in a + c + u: | ||
mw[f] = "" | ||||
|
r276 | mfw[f] = is_exec(self.wjoin(f)) | ||
|
r232 | for f in d: | ||
|
r254 | if f in mw: del mw[f] | ||
|
r232 | |||
for f, n in mw.iteritems(): | ||||
if f in m2: | ||||
|
r277 | s = 0 | ||
|
r296 | # are files different? | ||
|
r232 | if n != m2[f]: | ||
|
r254 | a = ma.get(f, nullid) | ||
|
r296 | # are both different from the ancestor? | ||
|
r254 | if n != a and m2[f] != a: | ||
|
r273 | self.ui.debug(" %s versions differ, resolve\n" % f) | ||
|
r254 | merge[f] = (m1.get(f, nullid), m2[f]) | ||
|
r276 | # merge executable bits | ||
# "if we changed or they changed, change in merge" | ||||
a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | ||||
mode = ((a^b) | (a^c)) ^ a | ||||
merge[f] = (m1.get(f, nullid), m2[f], mode) | ||||
|
r277 | s = 1 | ||
|
r305 | # are we clobbering? | ||
# is remote's version newer? | ||||
# or are we going back in time? | ||||
elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): | ||||
|
r273 | self.ui.debug(" remote %s is newer, get\n" % f) | ||
|
r254 | get[f] = m2[f] | ||
|
r277 | s = 1 | ||
|
r305 | else: | ||
mark[f] = 1 | ||||
|
r277 | |||
if not s and mfw[f] != mf2[f]: | ||||
if force: | ||||
self.ui.debug(" updating permissions for %s\n" % f) | ||||
set_exec(self.wjoin(f), mf2[f]) | ||||
else: | ||||
a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | ||||
mode = ((a^b) | (a^c)) ^ a | ||||
if mode != b: | ||||
self.ui.debug(" updating permissions for %s\n" % f) | ||||
set_exec(self.wjoin(f), mode) | ||||
|
r305 | mark[f] = 1 | ||
|
r232 | del m2[f] | ||
elif f in ma: | ||||
|
r275 | if not force and n != ma[f]: | ||
|
r232 | r = self.ui.prompt( | ||
(" local changed %s which remote deleted\n" % f) + | ||||
"(k)eep or (d)elete?", "[kd]", "k") | ||||
if r == "d": | ||||
remove.append(f) | ||||
else: | ||||
self.ui.debug("other deleted %s\n" % f) | ||||
|
r254 | remove.append(f) # other deleted it | ||
|
r232 | else: | ||
|
r254 | if n == m1.get(f, nullid): # same as parent | ||
|
r383 | if p2 == pa: # going backwards? | ||
self.ui.debug("remote deleted %s\n" % f) | ||||
remove.append(f) | ||||
else: | ||||
self.ui.debug("local created %s, keeping\n" % f) | ||||
|
r254 | else: | ||
self.ui.debug("working dir created %s, keeping\n" % f) | ||||
|
r46 | |||
|
r232 | for f, n in m2.iteritems(): | ||
|
r256 | if f[0] == "/": continue | ||
|
r275 | if not force and f in ma and n != ma[f]: | ||
r = self.ui.prompt( | ||||
("remote changed %s which local deleted\n" % f) + | ||||
"(k)eep or (d)elete?", "[kd]", "k") | ||||
if r == "d": remove.append(f) | ||||
|
r232 | else: | ||
|
r254 | self.ui.debug("remote created %s\n" % f) | ||
|
r232 | get[f] = n | ||
del mw, m1, m2, ma | ||||
|
r275 | if force: | ||
for f in merge: | ||||
get[f] = merge[f][1] | ||||
merge = {} | ||||
|
r305 | if pa == p1 or pa == p2: | ||
|
r254 | # we don't need to do any magic, just jump to the new rev | ||
mode = 'n' | ||||
p1, p2 = p2, nullid | ||||
else: | ||||
|
r275 | if not allow: | ||
|
r305 | self.ui.status("this update spans a branch" + | ||
" affecting the following files:\n") | ||||
fl = merge.keys() + get.keys() | ||||
fl.sort() | ||||
for f in fl: | ||||
cf = "" | ||||
if f in merge: cf = " (resolve)" | ||||
self.ui.status(" %s%s\n" % (f, cf)) | ||||
self.ui.warn("aborting update spanning branches!\n") | ||||
self.ui.status("(use update -m to perform a branch merge)\n") | ||||
|
r275 | return 1 | ||
|
r254 | # we have to remember what files we needed to get/change | ||
# because any file that's different from either one of its | ||||
# parents must be in the changeset | ||||
mode = 'm' | ||||
|
r305 | self.dirstate.update(mark.keys(), "m") | ||
|
r254 | |||
|
r232 | self.dirstate.setparents(p1, p2) | ||
|
r191 | |||
|
r232 | # get the files we don't need to change | ||
files = get.keys() | ||||
files.sort() | ||||
for f in files: | ||||
if f[0] == "/": continue | ||||
|
r273 | self.ui.note("getting %s\n" % f) | ||
|
r276 | t = self.file(f).read(get[f]) | ||
|
r232 | try: | ||
|
r291 | self.wfile(f, "w").write(t) | ||
|
r232 | except IOError: | ||
|
r297 | os.makedirs(os.path.dirname(self.wjoin(f))) | ||
|
r291 | self.wfile(f, "w").write(t) | ||
set_exec(self.wjoin(f), mf2[f]) | ||||
|
r254 | self.dirstate.update([f], mode) | ||
|
r46 | |||
|
r232 | # merge the tricky bits | ||
files = merge.keys() | ||||
files.sort() | ||||
for f in files: | ||||
|
r256 | self.ui.status("merging %s\n" % f) | ||
|
r276 | m, o, flag = merge[f] | ||
|
r232 | self.merge3(f, m, o) | ||
|
r297 | set_exec(self.wjoin(f), flag) | ||
|
r254 | self.dirstate.update([f], 'm') | ||
|
r232 | |||
for f in remove: | ||||
self.ui.note("removing %s\n" % f) | ||||
|
r254 | os.unlink(f) | ||
if mode == 'n': | ||||
self.dirstate.forget(remove) | ||||
else: | ||||
self.dirstate.update(remove, 'r') | ||||
|
r232 | |||
def merge3(self, fn, my, other): | ||||
"""perform a 3-way merge in the working directory""" | ||||
|
r249 | |||
|
r96 | def temp(prefix, node): | ||
pre = "%s~%s." % (os.path.basename(fn), prefix) | ||||
(fd, name) = tempfile.mkstemp("", pre) | ||||
f = os.fdopen(fd, "w") | ||||
f.write(fl.revision(node)) | ||||
f.close() | ||||
return name | ||||
|
r232 | fl = self.file(fn) | ||
|
r96 | base = fl.ancestor(my, other) | ||
|
r244 | a = self.wjoin(fn) | ||
|
r346 | b = temp("base", base) | ||
c = temp("other", other) | ||||
|
r96 | |||
|
r232 | self.ui.note("resolving %s\n" % fn) | ||
self.ui.debug("file %s: other %s ancestor %s\n" % | ||||
(fn, short(other), short(base))) | ||||
|
r96 | |||
|
r240 | cmd = os.environ.get("HGMERGE", "hgmerge") | ||
r = os.system("%s %s %s %s" % (cmd, a, b, c)) | ||||
|
r232 | if r: | ||
|
r275 | self.ui.warn("merging %s failed!\n" % fn) | ||
|
r232 | |||
os.unlink(b) | ||||
os.unlink(c) | ||||
|
r96 | |||
|
r247 | def verify(self): | ||
filelinkrevs = {} | ||||
filenodes = {} | ||||
changesets = revisions = files = 0 | ||||
errors = 0 | ||||
|
r302 | seen = {} | ||
|
r247 | self.ui.status("checking changesets\n") | ||
for i in range(self.changelog.count()): | ||||
changesets += 1 | ||||
n = self.changelog.node(i) | ||||
|
r302 | if n in seen: | ||
self.ui.warn("duplicate changeset at revision %d\n" % i) | ||||
errors += 1 | ||||
seen[n] = 1 | ||||
|
r247 | for p in self.changelog.parents(n): | ||
if p not in self.changelog.nodemap: | ||||
self.ui.warn("changeset %s has unknown parent %s\n" % | ||||
(short(n), short(p))) | ||||
errors += 1 | ||||
try: | ||||
changes = self.changelog.read(n) | ||||
except Exception, inst: | ||||
self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) | ||||
errors += 1 | ||||
for f in changes[3]: | ||||
filelinkrevs.setdefault(f, []).append(i) | ||||
|
r302 | seen = {} | ||
|
r247 | self.ui.status("checking manifests\n") | ||
for i in range(self.manifest.count()): | ||||
n = self.manifest.node(i) | ||||
|
r302 | if n in seen: | ||
self.ui.warn("duplicate manifest at revision %d\n" % i) | ||||
errors += 1 | ||||
seen[n] = 1 | ||||
|
r247 | for p in self.manifest.parents(n): | ||
if p not in self.manifest.nodemap: | ||||
self.ui.warn("manifest %s has unknown parent %s\n" % | ||||
(short(n), short(p))) | ||||
errors += 1 | ||||
try: | ||||
delta = mdiff.patchtext(self.manifest.delta(n)) | ||||
except KeyboardInterrupt: | ||||
print "aborted" | ||||
sys.exit(0) | ||||
except Exception, inst: | ||||
self.ui.warn("unpacking manifest %s: %s\n" | ||||
% (short(n), inst)) | ||||
errors += 1 | ||||
ff = [ l.split('\0') for l in delta.splitlines() ] | ||||
for f, fn in ff: | ||||
|
r284 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 | ||
|
r247 | |||
self.ui.status("crosschecking files in changesets and manifests\n") | ||||
for f in filenodes: | ||||
if f not in filelinkrevs: | ||||
self.ui.warn("file %s in manifest but not in changesets\n" % f) | ||||
errors += 1 | ||||
for f in filelinkrevs: | ||||
if f not in filenodes: | ||||
self.ui.warn("file %s in changeset but not in manifest\n" % f) | ||||
errors += 1 | ||||
self.ui.status("checking files\n") | ||||
ff = filenodes.keys() | ||||
ff.sort() | ||||
for f in ff: | ||||
if f == "/dev/null": continue | ||||
files += 1 | ||||
fl = self.file(f) | ||||
nodes = { nullid: 1 } | ||||
|
r302 | seen = {} | ||
|
r247 | for i in range(fl.count()): | ||
revisions += 1 | ||||
n = fl.node(i) | ||||
|
r302 | if n in seen: | ||
self.ui.warn("%s: duplicate revision %d\n" % (f, i)) | ||||
errors += 1 | ||||
|
r247 | if n not in filenodes[f]: | ||
self.ui.warn("%s: %d:%s not in manifests\n" | ||||
% (f, i, short(n))) | ||||
print len(filenodes[f].keys()), fl.count(), f | ||||
errors += 1 | ||||
else: | ||||
del filenodes[f][n] | ||||
flr = fl.linkrev(n) | ||||
if flr not in filelinkrevs[f]: | ||||
self.ui.warn("%s:%s points to unexpected changeset %d\n" | ||||
% (f, short(n), fl.linkrev(n))) | ||||
errors += 1 | ||||
else: | ||||
filelinkrevs[f].remove(flr) | ||||
# verify contents | ||||
try: | ||||
t = fl.read(n) | ||||
except Exception, inst: | ||||
self.ui.warn("unpacking file %s %s: %s\n" | ||||
% (f, short(n), inst)) | ||||
errors += 1 | ||||
# verify parents | ||||
(p1, p2) = fl.parents(n) | ||||
if p1 not in nodes: | ||||
self.ui.warn("file %s:%s unknown parent 1 %s" % | ||||
(f, short(n), short(p1))) | ||||
errors += 1 | ||||
if p2 not in nodes: | ||||
self.ui.warn("file %s:%s unknown parent 2 %s" % | ||||
(f, short(n), short(p1))) | ||||
errors += 1 | ||||
nodes[n] = 1 | ||||
# cross-check | ||||
for node in filenodes[f]: | ||||
self.ui.warn("node %s in manifests not in %s\n" | ||||
% (hex(n), f)) | ||||
errors += 1 | ||||
self.ui.status("%d files, %d changesets, %d total revisions\n" % | ||||
(files, changesets, revisions)) | ||||
if errors: | ||||
self.ui.warn("%d integrity errors encountered!\n" % errors) | ||||
return 1 | ||||
|
r60 | class remoterepository: | ||
def __init__(self, ui, path): | ||||
|
r176 | self.url = path | ||
|
r60 | self.ui = ui | ||
|
r321 | no_list = [ "localhost", "127.0.0.1" ] | ||
host = ui.config("http_proxy", "host") | ||||
user = ui.config("http_proxy", "user") | ||||
passwd = ui.config("http_proxy", "passwd") | ||||
no = ui.config("http_proxy", "no") | ||||
if no: | ||||
no_list = no_list + no.split(",") | ||||
no_proxy = 0 | ||||
for h in no_list: | ||||
if (path.startswith("http://" + h + "/") or | ||||
path.startswith("http://" + h + ":") or | ||||
path == "http://" + h): | ||||
no_proxy = 1 | ||||
# Note: urllib2 takes proxy values from the environment and those will | ||||
# take precedence | ||||
proxy_handler = urllib2.BaseHandler() | ||||
if host and not no_proxy: | ||||
proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) | ||||
authinfo = None | ||||
if user and passwd: | ||||
passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | ||||
passmgr.add_password(None, host, user, passwd) | ||||
authinfo = urllib2.ProxyBasicAuthHandler(passmgr) | ||||
opener = urllib2.build_opener(proxy_handler, authinfo) | ||||
urllib2.install_opener(opener) | ||||
|
r60 | |||
def do_cmd(self, cmd, **args): | ||||
|
r83 | self.ui.debug("sending %s command\n" % cmd) | ||
|
r60 | q = {"cmd": cmd} | ||
q.update(args) | ||||
qs = urllib.urlencode(q) | ||||
cu = "%s?%s" % (self.url, qs) | ||||
|
r321 | return urllib2.urlopen(cu) | ||
|
r60 | |||
|
r222 | def heads(self): | ||
d = self.do_cmd("heads").read() | ||||
try: | ||||
return map(bin, d[:-1].split(" ")) | ||||
except: | ||||
self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | ||||
raise | ||||
|
r60 | def branches(self, nodes): | ||
n = " ".join(map(hex, nodes)) | ||||
|
r65 | d = self.do_cmd("branches", nodes=n).read() | ||
|
r217 | try: | ||
br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | ||||
return br | ||||
except: | ||||
self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | ||||
raise | ||||
|
r60 | |||
def between(self, pairs): | ||||
n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | ||||
|
r65 | d = self.do_cmd("between", pairs=n).read() | ||
|
r217 | try: | ||
p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | ||||
return p | ||||
except: | ||||
self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | ||||
raise | ||||
|
r60 | |||
def changegroup(self, nodes): | ||||
n = " ".join(map(hex, nodes)) | ||||
|
r65 | zd = zlib.decompressobj() | ||
f = self.do_cmd("changegroup", roots=n) | ||||
|
r192 | bytes = 0 | ||
|
r65 | while 1: | ||
d = f.read(4096) | ||||
|
r192 | bytes += len(d) | ||
|
r65 | if not d: | ||
yield zd.flush() | ||||
break | ||||
yield zd.decompress(d) | ||||
|
r192 | self.ui.note("%d bytes of data transfered\n" % bytes) | ||
|
r60 | |||
def repository(ui, path=None, create=0): | ||||
|
r176 | if path and path[:7] == "http://": | ||
return remoterepository(ui, path) | ||||
|
r60 | if path and path[:5] == "hg://": | ||
|
r176 | return remoterepository(ui, path.replace("hg://", "http://")) | ||
if path and path[:11] == "old-http://": | ||||
return localrepository(ui, path.replace("old-http://", "http://")) | ||||
|
r60 | else: | ||
return localrepository(ui, path, create) | ||||