Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/changelog.py @ 4499:84ca5597a435
Obfuscate author in gitweb shortlog (issue578)
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Mon, 04 Jun 2007 22:05:47 +0200 |
parents | f9bbcebcacea |
children | dbc3846c09a1 |
rev | line source |
---|---|
1095 | 1 # changelog.py - changelog class for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
2858 | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
262 | 8 from revlog import * |
1400
cf9a1233738a
i18n first part: make '_' available for files who need it
Benoit Boissinot <benoit.boissinot@ens-lyon.org
parents:
1364
diff
changeset
|
9 from i18n import gettext as _ |
1321
b47f96a178a3
Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1202
diff
changeset
|
10 from demandload import demandload |
b47f96a178a3
Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1202
diff
changeset
|
11 demandload(globals(), "os time util") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
12 |
3224
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
13 def _string_escape(text): |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
14 """ |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
15 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
16 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
17 >>> s |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
18 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
19 >>> res = _string_escape(s) |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
20 >>> s == _string_unescape(res) |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
21 True |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
22 """ |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
23 # subset of the string_escape codec |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
24 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
25 return text.replace('\0', '\\0') |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
26 |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
27 def _string_unescape(text): |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
28 return text.decode('string_escape') |
394ac87f3b74
[extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3074
diff
changeset
|
29 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
30 class changelog(revlog): |
2142
8a1e2a9c7013
Replaced 0 with REVLOGV0 where this meaning is used.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2137
diff
changeset
|
31 def __init__(self, opener, defversion=REVLOGV0): |
2072 | 32 revlog.__init__(self, opener, "00changelog.i", "00changelog.d", |
33 defversion) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
34 |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
35 def decode_extra(self, text): |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
36 extra = {} |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
37 for l in text.split('\0'): |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
38 if not l: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
39 continue |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
40 k, v = _string_unescape(l).split(':', 1) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
41 extra[k] = v |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
42 return extra |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
43 |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
44 def encode_extra(self, d): |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
45 items = [_string_escape(":".join(t)) for t in d.iteritems()] |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
46 return "\0".join(items) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
47 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
48 def extract(self, text): |
3074
ad6aecaf4eed
document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2858
diff
changeset
|
49 """ |
ad6aecaf4eed
document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2858
diff
changeset
|
50 format used: |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
51 nodeid\n : manifest node in ascii |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
52 user\n : user, no \n or \r allowed |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
53 time tz extra\n : date (time is int or float, timezone is int) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
54 : extra is metadatas, encoded and separated by '\0' |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
55 : older versions ignore it |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
56 files\n\n : files modified by the cset, no \n or \r allowed |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
57 (.*) : comment (free text, ideally utf-8) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
58 |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
59 changelog v0 doesn't use extra |
3074
ad6aecaf4eed
document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2858
diff
changeset
|
60 """ |
37 | 61 if not text: |
4204
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3772
diff
changeset
|
62 return (nullid, "", (0, 0), [], "", {'branch': 'default'}) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
63 last = text.index("\n\n") |
3772
29d91e57d055
Handle transcoding of username and description in changelog
Matt Mackall <mpm@selenic.com>
parents:
3427
diff
changeset
|
64 desc = util.tolocal(text[last + 2:]) |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
65 l = text[:last].split('\n') |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
66 manifest = bin(l[0]) |
3772
29d91e57d055
Handle transcoding of username and description in changelog
Matt Mackall <mpm@selenic.com>
parents:
3427
diff
changeset
|
67 user = util.tolocal(l[1]) |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
68 |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
69 extra_data = l[2].split(' ', 2) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
70 if len(extra_data) != 3: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
71 time = float(extra_data.pop(0)) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
72 try: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
73 # various tools did silly things with the time zone field. |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
74 timezone = int(extra_data[0]) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
75 except: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
76 timezone = 0 |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
77 extra = {} |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
78 else: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
79 time, timezone, extra = extra_data |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
80 time, timezone = float(time), int(timezone) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
81 extra = self.decode_extra(extra) |
4204
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3772
diff
changeset
|
82 if not extra.get('branch'): |
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3772
diff
changeset
|
83 extra['branch'] = 'default' |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
84 files = l[3:] |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
85 return (manifest, user, (time, timezone), files, desc, extra) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
86 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
87 def read(self, node): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
88 return self.extract(self.revision(node)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
89 |
203 | 90 def add(self, manifest, list, desc, transaction, p1=None, p2=None, |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
91 user=None, date=None, extra={}): |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
92 |
3772
29d91e57d055
Handle transcoding of username and description in changelog
Matt Mackall <mpm@selenic.com>
parents:
3427
diff
changeset
|
93 user, desc = util.fromlocal(user), util.fromlocal(desc) |
29d91e57d055
Handle transcoding of username and description in changelog
Matt Mackall <mpm@selenic.com>
parents:
3427
diff
changeset
|
94 |
1195
f92af8d53330
Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1095
diff
changeset
|
95 if date: |
2523
4ab59a3acd16
validate the resulting date in parsedate
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2522
diff
changeset
|
96 parseddate = "%d %d" % util.parsedate(date) |
1195
f92af8d53330
Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1095
diff
changeset
|
97 else: |
2522
85f796baab10
Allow the use of human readable dates (issue 251)
Jose M. Prieto <jmprieto@gmx.net>
parents:
2142
diff
changeset
|
98 parseddate = "%d %d" % util.makedate() |
4204
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3772
diff
changeset
|
99 if extra and extra.get("branch") in ("default", ""): |
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3772
diff
changeset
|
100 del extra["branch"] |
3225
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
101 if extra: |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
102 extra = self.encode_extra(extra) |
2f35961854fb
[extendedchangelog] add extra metadata in the changelog entry
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3224
diff
changeset
|
103 parseddate = "%s %s" % (parseddate, extra) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
104 list.sort() |
2522
85f796baab10
Allow the use of human readable dates (issue 251)
Jose M. Prieto <jmprieto@gmx.net>
parents:
2142
diff
changeset
|
105 l = [hex(manifest), user, parseddate] + list + ["", desc] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
106 text = "\n".join(l) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
107 return self.addrevision(text, transaction, self.count(), p1, p2) |