filelog.py
68 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
/ mercurial / filelog.py
mpm@selenic.com
|
r1089 | # filelog.py - file history class for mercurial | ||
# | ||||
Thomas Arendsen Hein
|
r4635 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||
mpm@selenic.com
|
r1089 | # | ||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
# GNU General Public License version 2, incorporated herein by reference. | ||||
mpm@selenic.com
|
r1089 | |||
Matt Mackall
|
r7634 | import revlog | ||
mpm@selenic.com
|
r1089 | |||
Matt Mackall
|
r7634 | class filelog(revlog.revlog): | ||
Matt Mackall
|
r4258 | def __init__(self, opener, path): | ||
Matt Mackall
|
r7634 | revlog.revlog.__init__(self, opener, | ||
Benoit Boissinot
|
r8531 | "/".join(("data", path + ".i"))) | ||
mpm@selenic.com
|
r1089 | |||
def read(self, node): | ||||
t = self.revision(node) | ||||
if not t.startswith('\1\n'): | ||||
return t | ||||
Benoit Boissinot
|
r2579 | s = t.index('\1\n', 2) | ||
mpm@selenic.com
|
r1089 | return t[s+2:] | ||
Matt Mackall
|
r3123 | def _readmeta(self, node): | ||
mpm@selenic.com
|
r1089 | t = self.revision(node) | ||
if not t.startswith('\1\n'): | ||||
mpm@selenic.com
|
r1116 | return {} | ||
Benoit Boissinot
|
r2579 | s = t.index('\1\n', 2) | ||
mpm@selenic.com
|
r1089 | mt = t[2:s] | ||
mpm@selenic.com
|
r1116 | m = {} | ||
mpm@selenic.com
|
r1089 | 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.startswith('\1\n'): | ||||
mt = "" | ||||
if meta: | ||||
Dirkjan Ochtman
|
r7622 | mt = ["%s: %s\n" % (k, v) for k, v in meta.iteritems()] | ||
twaldmann@thinkmo.de
|
r1540 | text = "\1\n%s\1\n%s" % ("".join(mt), text) | ||
mpm@selenic.com
|
r1089 | return self.addrevision(text, transaction, link, p1, p2) | ||
mpm@selenic.com
|
r1116 | def renamed(self, node): | ||
Matt Mackall
|
r7634 | if self.parents(node)[0] != revlog.nullid: | ||
mpm@selenic.com
|
r1116 | return False | ||
Matt Mackall
|
r3123 | m = self._readmeta(node) | ||
Christian Ebert
|
r5915 | if m and "copy" in m: | ||
Matt Mackall
|
r7634 | return (m["copy"], revlog.bin(m["copyrev"])) | ||
mpm@selenic.com
|
r1116 | return False | ||
Matt Mackall
|
r2898 | def size(self, rev): | ||
"""return the size of a given revision""" | ||||
# for revisions with renames, we have to go the slow way | ||||
node = self.node(rev) | ||||
if self.renamed(node): | ||||
return len(self.read(node)) | ||||
Matt Mackall
|
r7634 | return revlog.revlog.size(self, rev) | ||
Matt Mackall
|
r2898 | |||
Matt Mackall
|
r2887 | def cmp(self, node, text): | ||
"""compare text with a given file revision""" | ||||
# for renames, we have to go the slow way | ||||
if self.renamed(node): | ||||
t2 = self.read(node) | ||||
Matt Mackall
|
r2895 | return t2 != text | ||
Matt Mackall
|
r2887 | |||
Matt Mackall
|
r7634 | return revlog.revlog.cmp(self, node, text) | ||