mercurial/changelog.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Thu, 08 Dec 2005 15:12:02 +0100
changeset 1677 11d12bd6e1dc
parent 1402 9d2c2e6b32b5
child 1678 b345cc4c22c0
permissions -rw-r--r--
cleanup of revlog.group when repository is local revlog.group cached every chunk from the revlog, the behaviour was needed to minimize the roundtrip with old-http. The patch export the information that the repository is local or not from the repository object down to the revlog. Then it uses the workaround for old-http only if the repository is non-local. The memory used server side when pulling goes down to less than 30Mo maximum whereas without the patch more than 160Mo was used when cloning the linux kernel repository. The time used by cloning is roughly the same (although some caching could be implemented if needed): before 110.25user 20.90system 2:52.00elapsed 76%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+708707minor)pagefaults 0swaps after 112.85user 22.98system 2:50.66elapsed 79%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+862862minor)pagefaults 0swaps
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
#
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     3
# Copyright 2005 Matt Mackall <mpm@selenic.com>
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):
1677
11d12bd6e1dc cleanup of revlog.group when repository is local
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
    14
    def __init__(self, opener, local=True):
11d12bd6e1dc cleanup of revlog.group when repository is local
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
    15
        revlog.__init__(self, opener, "00changelog.i", "00changelog.d",
11d12bd6e1dc cleanup of revlog.group when repository is local
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1402
diff changeset
    16
                        local=local)
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):
37
a8811676c85a Move hex/bin bits to revlog
mpm@selenic.com
parents: 33
diff changeset
    19
        if not text:
1364
0f25830f6bc3 Fix data reported for the nullid changeset
Matt Mackall <mpm@selenic.com>
parents: 1327
diff changeset
    20
            return (nullid, "", (0, 0), [], "")
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    21
        last = text.index("\n\n")
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    22
        desc = text[last + 2:]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    23
        l = text[:last].splitlines()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    24
        manifest = bin(l[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    25
        user = l[1]
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    26
        date = l[2].split(' ')
1327
085e3fc189b6 Some repos represent a date as a float.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1321
diff changeset
    27
        time = float(date.pop(0))
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    28
        try:
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    29
            # 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
    30
            timezone = int(date[0])
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    31
        except:
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    32
            timezone = 0
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    33
        files = l[3:]
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    34
        return (manifest, user, (time, timezone), files, desc)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    35
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    36
    def read(self, node):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    37
        return self.extract(self.revision(node))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    38
203
0b486b5e0796 hg rawcommit command
mpm@selenic.com
parents: 200
diff changeset
    39
    def add(self, manifest, list, desc, transaction, p1=None, p2=None,
0b486b5e0796 hg rawcommit command
mpm@selenic.com
parents: 200
diff changeset
    40
                  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
    41
        if date:
1196
3738e85ead07 Make date/timezone validation in changelog.add more robust. Add test.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1195
diff changeset
    42
            # validate explicit (probably user-specified) date and
1197
8deb69818e4b Date validation must check for 32-bit width. Don't use assert to check.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1196
diff changeset
    43
            # time zone offset. values must fit in signed 32 bits for
8deb69818e4b Date validation must check for 32-bit width. Don't use assert to check.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1196
diff changeset
    44
            # current 32-bit linux runtimes.
1202
71111d796e40 Commit date validation: more stringent checks, more useful error messages.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1197
diff changeset
    45
            try:
71111d796e40 Commit date validation: more stringent checks, more useful error messages.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1197
diff changeset
    46
                when, offset = map(int, date.split(' '))
71111d796e40 Commit date validation: more stringent checks, more useful error messages.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1197
diff changeset
    47
            except ValueError:
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
    48
                raise ValueError(_('invalid date: %r') % date)
1197
8deb69818e4b Date validation must check for 32-bit width. Don't use assert to check.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1196
diff changeset
    49
            if abs(when) > 0x7fffffff:
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
    50
                raise ValueError(_('date exceeds 32 bits: %d') % when)
1197
8deb69818e4b Date validation must check for 32-bit width. Don't use assert to check.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1196
diff changeset
    51
            if abs(offset) >= 43200:
1402
9d2c2e6b32b5 i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1400
diff changeset
    52
                raise ValueError(_('impossible time zone offset: %d') % offset)
1195
f92af8d53330 Validate user input of dates when adding a changelog entry.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1095
diff changeset
    53
        else:
1321
b47f96a178a3 Clean up date and timezone handling.
Bryan O'Sullivan <bos@serpentine.com>
parents: 1202
diff changeset
    54
            date = "%d %d" % util.makedate()
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    55
        list.sort()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    56
        l = [hex(manifest), user, date] + list + ["", desc]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    57
        text = "\n".join(l)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    58
        return self.addrevision(text, transaction, self.count(), p1, p2)