mercurial/manifest.py
author Matt Mackall <mpm@selenic.com>
Sun, 16 Jul 2006 02:59:20 -0500
changeset 2831 0b50a580be36
parent 2470 fe1689273f84
child 2832 e196aa1df169
permissions -rw-r--r--
Add manifestflags class
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents: 1072
diff changeset
     1
# manifest.py - manifest revision 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: 1098
diff changeset
     9
from i18n import gettext as _
262
3db700146536 implement demand loading hack
mpm@selenic.com
parents: 256
diff changeset
    10
from demandload import *
2470
fe1689273f84 use demandload more.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2320
diff changeset
    11
demandload(globals(), "array bisect struct")
79
837d473d54d5 Add basic annotation support
mpm@selenic.com
parents: 78
diff changeset
    12
2831
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    13
class manifestflags(dict):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    14
    def __init__(self, mapping={}):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    15
        dict.__init__(self, mapping)
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    16
    def execf(self, f):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    17
        "test for executable in manifest flags"
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    18
        return self.get(f, False)
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    19
    def linkf(self, f):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    20
        "test for symlink in manifest flags"
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    21
        return False
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    22
    def set(self, f, execf=False, linkf=False):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    23
        self[f] = execf
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    24
    def copy(self):
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    25
        return manifestflags(dict.copy(self))
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    26
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    27
class manifest(revlog):
2142
8a1e2a9c7013 Replaced 0 with REVLOGV0 where this meaning is used.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2072
diff changeset
    28
    def __init__(self, opener, defversion=REVLOGV0):
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    29
        self.mapcache = None
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    30
        self.listcache = None
2072
74d3f5336b66 Implement revlogng.
mason@suse.com
parents: 1651
diff changeset
    31
        revlog.__init__(self, opener, "00manifest.i", "00manifest.d",
74d3f5336b66 Implement revlogng.
mason@suse.com
parents: 1651
diff changeset
    32
                        defversion)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    33
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    34
    def read(self, node):
313
e75ea4662d81 Minor caching improvement for manifest
mpm@selenic.com
parents: 312
diff changeset
    35
        if node == nullid: return {} # don't upset local cache
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    36
        if self.mapcache and self.mapcache[0] == node:
561
cdddf4652aec Fix dodiff/changes
mpm@selenic.com
parents: 557
diff changeset
    37
            return self.mapcache[1]
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    38
        text = self.revision(node)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    39
        map = {}
2831
0b50a580be36 Add manifestflags class
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    40
        flag = manifestflags()
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    41
        self.listcache = array.array('c', text)
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    42
        lines = text.splitlines(1)
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    43
        for l in lines:
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    44
            (f, n) = l.split('\0')
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    45
            map[f] = bin(n[:40])
276
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    46
            flag[f] = (n[40:-1] == "x")
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    47
        self.mapcache = (node, map, flag)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    48
        return map
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    49
276
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    50
    def readflags(self, node):
313
e75ea4662d81 Minor caching improvement for manifest
mpm@selenic.com
parents: 312
diff changeset
    51
        if node == nullid: return {} # don't upset local cache
358
9f4077d7ef6f [PATCH] manifest.readflags performance buglet
mpm@selenic.com
parents: 350
diff changeset
    52
        if not self.mapcache or self.mapcache[0] != node:
276
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    53
            self.read(node)
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    54
        return self.mapcache[2]
10e325db7347 add tracking of execute permissions
mpm@selenic.com
parents: 275
diff changeset
    55
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    56
    def diff(self, a, b):
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    57
        return mdiff.textdiff(str(a), str(b))
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
    58
2320
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    59
    def _search(self, m, s, lo=0, hi=None):
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    60
        '''return a tuple (start, end) that says where to find s within m.
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    61
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    62
        If the string is found m[start:end] are the line containing
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    63
        that string.  If start == end the string was not found and
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    64
        they indicate the proper sorted insertion point.  This was
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    65
        taken from bisect_left, and modified to find line start/end as
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    66
        it goes along.
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    67
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    68
        m should be a buffer or a string
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    69
        s is a string'''
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    70
        def advance(i, c):
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    71
            while i < lenm and m[i] != c:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    72
                i += 1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    73
            return i
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    74
        lenm = len(m)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    75
        if not hi:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    76
            hi = lenm
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    77
        while lo < hi:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    78
            mid = (lo + hi) // 2
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    79
            start = mid
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    80
            while start > 0 and m[start-1] != '\n':
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    81
                start -= 1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    82
            end = advance(start, '\0')
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    83
            if m[start:end] < s:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    84
                # we know that after the null there are 40 bytes of sha1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    85
                # this translates to the bisect lo = mid + 1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    86
                lo = advance(end + 40, '\n') + 1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    87
            else:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    88
                # this translates to the bisect hi = mid
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    89
                hi = start
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    90
        end = advance(lo, '\0')
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    91
        found = m[lo:end]
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    92
        if cmp(s, found) == 0:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    93
            # we know that after the null there are 40 bytes of sha1
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    94
            end = advance(end + 40, '\n')
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    95
            return (lo, end+1)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    96
        else:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    97
            return (lo, lo)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    98
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
    99
    def find(self, node, f):
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   100
        '''look up entry for a single file efficiently.
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   101
        return (node, flag) pair if found, (None, None) if not.'''
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   102
        if self.mapcache and node == self.mapcache[0]:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   103
            return self.mapcache[1].get(f), self.mapcache[2].get(f)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   104
        text = self.revision(node)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   105
        start, end = self._search(text, f)
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   106
        if start == end:
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   107
            return None, None
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   108
        l = text[start:end]
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   109
        f, n = l.split('\0')
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   110
        return bin(n[:40]), n[40:-1] == 'x'
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   111
741
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   112
    def add(self, map, flags, transaction, link, p1=None, p2=None,
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   113
            changed=None):
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   114
        # apply the changes collected during the bisect loop to our addlist
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   115
        # return a delta suitable for addrevision
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   116
        def addlistdelta(addlist, x):
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   117
            # start from the bottom up
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   118
            # so changes to the offsets don't mess things up.
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   119
            i = len(x)
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   120
            while i > 0:
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   121
                i -= 1
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   122
                start = x[i][0]
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   123
                end = x[i][1]
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   124
                if x[i][2]:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   125
                    addlist[start:end] = array.array('c', x[i][2])
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   126
                else:
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   127
                    del addlist[start:end]
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   128
            return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2] \
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   129
                            for d in x ])
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   130
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   131
        # if we're using the listcache, make sure it is valid and
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   132
        # parented by the same node we're diffing against
741
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   133
        if not changed or not self.listcache or not p1 or \
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   134
               self.mapcache[0] != p1:
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   135
            files = map.keys()
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   136
            files.sort()
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   137
1651
cf40d2a30fef Fix comment syntax
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   138
            # if this is changed to support newlines in filenames,
cf40d2a30fef Fix comment syntax
Matt Mackall <mpm@selenic.com>
parents: 1650
diff changeset
   139
            # be sure to check the templates/ dir again (especially *-raw.tmpl)
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   140
            text = ["%s\000%s%s\n" %
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   141
                            (f, hex(map[f]), flags[f] and "x" or '')
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   142
                            for f in files]
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   143
            self.listcache = array.array('c', "".join(text))
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   144
            cachedelta = None
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   145
        else:
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   146
            addlist = self.listcache
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   147
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   148
            # combine the changed lists into one list for sorting
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   149
            work = [[x, 0] for x in changed[0]]
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   150
            work[len(work):] = [[x, 1] for x in changed[1]]
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   151
            work.sort()
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   152
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   153
            delta = []
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   154
            dstart = None
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   155
            dend = None
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   156
            dline = [""]
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   157
            start = 0
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   158
            # zero copy representation of addlist as a buffer
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   159
            addbuf = buffer(addlist)
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   160
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   161
            # start with a readonly loop that finds the offset of
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   162
            # each line and creates the deltas
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   163
            for w in work:
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   164
                f = w[0]
741
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   165
                # bs will either be the index of the item or the insert point
2320
dbdce3b99988 fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2142
diff changeset
   166
                start, end = self._search(addbuf, f, start)
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   167
                if w[1] == 0:
741
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   168
                    l = "%s\000%s%s\n" % (f, hex(map[f]),
156dc2f3be7f Fix some line wrapping
mpm@selenic.com
parents: 740
diff changeset
   169
                                          flags[f] and "x" or '')
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   170
                else:
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   171
                    l = ""
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   172
                if start == end and w[1] == 1:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   173
                    # item we want to delete was not found, error out
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   174
                    raise AssertionError(
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
   175
                            _("failed to remove %s from manifest\n") % f)
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   176
                if dstart != None and dstart <= start and dend >= start:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   177
                    if dend < end:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   178
                        dend = end
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   179
                    if l:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   180
                        dline.append(l)
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   181
                else:
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   182
                    if dstart != None:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   183
                        delta.append([dstart, dend, "".join(dline)])
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   184
                    dstart = start
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   185
                    dend = end
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   186
                    dline = [l]
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   187
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   188
            if dstart != None:
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   189
                delta.append([dstart, dend, "".join(dline)])
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   190
            # apply the delta to the addlist, and get a delta for addrevision
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   191
            cachedelta = addlistdelta(addlist, delta)
644
6ebe118280bd Performance enhancements for manifest.add()
mason@suse.com
parents: 639
diff changeset
   192
1534
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   193
            # the delta is only valid if we've been processing the tip revision
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   194
            if self.mapcache[0] != self.tip():
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   195
                cachedelta = None
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   196
            self.listcache = addlist
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   197
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   198
        n = self.addrevision(buffer(self.listcache), transaction, link, p1,  \
80a3d6a0af71 Optimize manifest.add
mason@suse.com
parents: 1451
diff changeset
   199
                             p2, cachedelta)
302
498fb0fa2795 various fixups for git import
mpm@selenic.com
parents: 299
diff changeset
   200
        self.mapcache = (n, map, flags)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   201
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   202
        return n