comparison mercurial/changelog.py @ 16459:baa06fb69ece stable

merge default into stable for 2.2 code freeze
author Matt Mackall <mpm@selenic.com>
date Tue, 17 Apr 2012 17:56:36 -0500
parents aa6821a7b52f
children bc84a1aeaf5a
comparison
equal deleted inserted replaced
16450:c9c8c9053119 16459:baa06fb69ece
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from node import bin, hex, nullid 8 from node import bin, hex, nullid
9 from i18n import _ 9 from i18n import _
10 import util, error, revlog, encoding 10 import util, error, revlog, encoding
11
12 _defaultextra = {'branch': 'default'}
11 13
12 def _string_escape(text): 14 def _string_escape(text):
13 """ 15 """
14 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} 16 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)}
15 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d 17 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d
24 return text.replace('\0', '\\0') 26 return text.replace('\0', '\\0')
25 27
26 def decodeextra(text): 28 def decodeextra(text):
27 """ 29 """
28 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'})) 30 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'}))
29 {'foo': 'bar', 'baz': '\\x002'} 31 {'foo': 'bar', 'baz': '\\x002', 'branch': 'default'}
30 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(92) + chr(0) + '2'})) 32 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(92) + chr(0) + '2'}))
31 {'foo': 'bar', 'baz': '\\\\\\x002'} 33 {'foo': 'bar', 'baz': '\\\\\\x002', 'branch': 'default'}
32 """ 34 """
33 extra = {} 35 extra = _defaultextra.copy()
34 for l in text.split('\0'): 36 for l in text.split('\0'):
35 if l: 37 if l:
36 if '\\0' in l: 38 if '\\0' in l:
37 # fix up \0 without getting into trouble with \\0 39 # fix up \0 without getting into trouble with \\0
38 l = l.replace('\\\\', '\\\\\n') 40 l = l.replace('\\\\', '\\\\\n')
189 191
190 changelog v0 doesn't use extra 192 changelog v0 doesn't use extra
191 """ 193 """
192 text = self.revision(node) 194 text = self.revision(node)
193 if not text: 195 if not text:
194 return (nullid, "", (0, 0), [], "", {'branch': 'default'}) 196 return (nullid, "", (0, 0), [], "", _defaultextra)
195 last = text.index("\n\n") 197 last = text.index("\n\n")
196 desc = encoding.tolocal(text[last + 2:]) 198 desc = encoding.tolocal(text[last + 2:])
197 l = text[:last].split('\n') 199 l = text[:last].split('\n')
198 manifest = bin(l[0]) 200 manifest = bin(l[0])
199 user = encoding.tolocal(l[1]) 201 user = encoding.tolocal(l[1])
200 202
201 extra_data = l[2].split(' ', 2) 203 tdata = l[2].split(' ', 2)
202 if len(extra_data) != 3: 204 if len(tdata) != 3:
203 time = float(extra_data.pop(0)) 205 time = float(tdata[0])
204 try: 206 try:
205 # various tools did silly things with the time zone field. 207 # various tools did silly things with the time zone field.
206 timezone = int(extra_data[0]) 208 timezone = int(tdata[1])
207 except ValueError: 209 except ValueError:
208 timezone = 0 210 timezone = 0
209 extra = {} 211 extra = _defaultextra
210 else: 212 else:
211 time, timezone, extra = extra_data 213 time, timezone = float(tdata[0]), int(tdata[1])
212 time, timezone = float(time), int(timezone) 214 extra = decodeextra(tdata[2])
213 extra = decodeextra(extra) 215
214 if not extra.get('branch'):
215 extra['branch'] = 'default'
216 files = l[3:] 216 files = l[3:]
217 return (manifest, user, (time, timezone), files, desc, extra) 217 return (manifest, user, (time, timezone), files, desc, extra)
218 218
219 def add(self, manifest, files, desc, transaction, p1, p2, 219 def add(self, manifest, files, desc, transaction, p1, p2,
220 user, date=None, extra=None): 220 user, date=None, extra=None):