mercurial/changelog.py
author Brendan Cully <brendan@kublai.com>
Sat, 30 Sep 2006 20:56:26 -0700
changeset 3219 9a478efc16cc
parent 3077 ad6aecaf4eed
child 3232 394ac87f3b74
permissions -rw-r--r--
filelog.annotate is now obsolete
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1095
0a18374c0769 changelog: adjust imports, comment
mpm@selenic.com
parents: 1094 1089
diff changeset
     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
#
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2523
diff changeset
     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
3db700146536 implement demand loading hack
mpm@selenic.com
parents: 256
diff changeset
     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
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    13
class changelog(revlog):
2142
8a1e2a9c7013 Replaced 0 with REVLOGV0 where this meaning is used.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2137
diff changeset
    14
    def __init__(self, opener, defversion=REVLOGV0):
2072
74d3f5336b66 Implement revlogng.
mason@suse.com
parents: 1402
diff changeset
    15
        revlog.__init__(self, opener, "00changelog.i", "00changelog.d",
74d3f5336b66 Implement revlogng.
mason@suse.com
parents: 1402
diff changeset
    16
                        defversion)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    17
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    18
    def extract(self, text):
3077
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    19
        """
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    20
        format used:
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    21
        nodeid\n  : manifest node in ascii
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    22
        user\n    : user, no \n or \r allowed
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    23
        time tz\n : date (time is int or float, timezone is int)
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    24
        files\n\n : files modified by the cset, no \n or \r allowed
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    25
        (.*)      : comment (free text, ideally utf-8)
ad6aecaf4eed document changelog format
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2859
diff changeset
    26
        """
37
a8811676c85a Move hex/bin bits to revlog
mpm@selenic.com
parents: 33
diff changeset
    27
        if not text:
1364
0f25830f6bc3 Fix data reported for the nullid changeset
Matt Mackall <mpm@selenic.com>
parents: 1327
diff changeset
    28
            return (nullid, "", (0, 0), [], "")
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    29
        last = text.index("\n\n")
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    30
        desc = text[last + 2:]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    31
        l = text[:last].splitlines()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    32
        manifest = bin(l[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    33
        user = l[1]
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    34
        date = l[2].split(' ')
1327
085e3fc189b6 Some repos represent a date as a float.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1321
diff changeset
    35
        time = float(date.pop(0))
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    36
        try:
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    37
            # various tools did silly things with the time zone field.
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    38
            timezone = int(date[0])
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    39
        except:
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    40
            timezone = 0
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    41
        files = l[3:]
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    42
        return (manifest, user, (time, timezone), files, desc)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    43
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    44
    def read(self, node):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    45
        return self.extract(self.revision(node))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    46
203
0b486b5e0796 hg rawcommit command
mpm@selenic.com
parents: 200
diff changeset
    47
    def add(self, manifest, list, desc, transaction, p1=None, p2=None,
0b486b5e0796 hg rawcommit command
mpm@selenic.com
parents: 200
diff changeset
    48
                  user=None, date=None):
1195
f92af8d53330 Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1095
diff changeset
    49
        if date:
2523
4ab59a3acd16 validate the resulting date in parsedate
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2522
diff changeset
    50
            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
    51
        else:
2522
85f796baab10 Allow the use of human readable dates (issue 251)
Jose M. Prieto <jmprieto@gmx.net>
parents: 2142
diff changeset
    52
            parseddate = "%d %d" % util.makedate()
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    53
        list.sort()
2522
85f796baab10 Allow the use of human readable dates (issue 251)
Jose M. Prieto <jmprieto@gmx.net>
parents: 2142
diff changeset
    54
        l = [hex(manifest), user, parseddate] + list + ["", desc]
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    55
        text = "\n".join(l)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    56
        return self.addrevision(text, transaction, self.count(), p1, p2)