[PATCH 2 of 2] [extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot
benoit.boissinot at ens-lyon.org
Thu Sep 28 19:16:22 UTC 2006
# HG changeset patch
# User Benoit Boissinot <benoit.boissinot at ens-lyon.org>
# Date 1159470952 -7200
# Node ID 235302cf918ce3e5212d7ce6154ad4f6b684fa6c
# Parent cf9d7203adc5e9d02d26f8f064b7aa92e07873cd
[extendedchangelog] add extra metadata in the changelog entry
- add a third item in the date field that holds arbitrary
key:value items
diff -r cf9d7203adc5 -r 235302cf918c mercurial/changelog.py
--- a/mercurial/changelog.py Thu Sep 28 21:04:56 2006 +0200
+++ b/mercurial/changelog.py Thu Sep 28 21:15:52 2006 +0200
@@ -32,41 +32,70 @@ class changelog(revlog):
revlog.__init__(self, opener, "00changelog.i", "00changelog.d",
defversion)
+ def decode_extra(self, text):
+ text = string_unescape(text)
+ extra = {}
+ for l in text.split('\0'):
+ if not l:
+ continue
+ k, v = l.split(':', 1)
+ extra[k] = v
+ return extra
+
+ def encode_extra(self, d):
+ text = "\0".join([":".join(t) for t in d.iteritems()])
+ return string_escape(text)
+
def extract(self, text):
"""
format used:
- nodeid\n : manifest node in ascii
- user\n : user, no \n or \r allowed
- time tz\n : date (time is int or float, timezone is int)
- files\n\n : files modified by the cset, no \n or \r allowed
- (.*) : comment (free text, ideally utf-8)
+ nodeid\n : manifest node in ascii
+ user\n : user, no \n or \r allowed
+ time tz extra\n : date (time is int or float, timezone is int)
+ : extra is metadatas, encoded and separated by '\0'
+ : older versions ignore it
+ files\n\n : files modified by the cset, no \n or \r allowed
+ (.*) : comment (free text, ideally utf-8)
+
+ changelog v0 doesn't use extra
"""
if not text:
return (nullid, "", (0, 0), [], "")
last = text.index("\n\n")
desc = text[last + 2:]
- l = text[:last].splitlines()
+ l = text[:last].split('\n')
manifest = bin(l[0])
user = l[1]
- date = l[2].split(' ')
- time = float(date.pop(0))
- try:
- # various tools did silly things with the time zone field.
- timezone = int(date[0])
- except:
- timezone = 0
+
+ extra_data = l[2].split(' ', 2)
+ if len(extra_data) != 3:
+ time = float(extra_data.pop(0))
+ try:
+ # various tools did silly things with the time zone field.
+ timezone = int(extra_data[0])
+ except:
+ timezone = 0
+ extra = {}
+ else:
+ time, timezone, extra = extra_data
+ time, timezone = float(time), int(timezone)
+ extra = self.decode_extra(extra)
files = l[3:]
- return (manifest, user, (time, timezone), files, desc)
+ return (manifest, user, (time, timezone), files, desc, extra)
def read(self, node):
return self.extract(self.revision(node))
def add(self, manifest, list, desc, transaction, p1=None, p2=None,
- user=None, date=None):
+ user=None, date=None, extra={}):
+
+ extra = self.encode_extra(extra)
if date:
parseddate = "%d %d" % util.parsedate(date)
else:
parseddate = "%d %d" % util.makedate()
+ if extra:
+ parseddate = "%s %s" % (parseddate, extra)
list.sort()
l = [hex(manifest), user, parseddate] + list + ["", desc]
text = "\n".join(l)
More information about the Mercurial
mailing list