mercurial/pure/parsers.py
author Augie Fackler <augie@google.com>
Wed, 08 Mar 2017 18:32:42 -0500
changeset 31266 8089de5fab89
parent 31220 37596c980662
child 31529 61ff3852f6ed
permissions -rw-r--r--
dispatch: add pagination of two more help cases I missed these in the last round anf Yuya spotted them in review. Thanks!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     1
# parsers.py - Python implementation of parsers.c
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     2
#
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     3
# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7945
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8225
diff changeset
     6
# GNU General Public License version 2 or any later version.
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     7
27339
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
     8
from __future__ import absolute_import
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
     9
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    10
import struct
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    11
import zlib
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    12
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    13
from .node import nullid
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 27339
diff changeset
    14
from . import pycompat
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 27339
diff changeset
    15
stringio = pycompat.stringio
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    16
31220
37596c980662 parsers: alias long to int on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29133
diff changeset
    17
if pycompat.ispy3:
37596c980662 parsers: alias long to int on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29133
diff changeset
    18
    long = int
37596c980662 parsers: alias long to int on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29133
diff changeset
    19
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    20
_pack = struct.pack
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    21
_unpack = struct.unpack
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    22
_compress = zlib.compress
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    23
_decompress = zlib.decompress
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    24
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    25
# Some code below makes tuples directly because it's more convenient. However,
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    26
# code outside this module should always use dirstatetuple.
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    27
def dirstatetuple(*x):
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    28
    # x is a tuple
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    29
    return x
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
    30
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    31
indexformatng = ">Qiiiiii20s12x"
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    32
indexfirst = struct.calcsize('Q')
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    33
sizeint = struct.calcsize('i')
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    34
indexsize = struct.calcsize(indexformatng)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    35
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    36
def gettype(q):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    37
    return int(q & 0xFFFF)
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
    38
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    39
def offset_type(offset, type):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    40
    return long(long(offset) << 16 | type)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    41
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    42
class BaseIndexObject(object):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    43
    def __len__(self):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    44
        return self._lgt + len(self._extra) + 1
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    45
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    46
    def insert(self, i, tup):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    47
        assert i == -1
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    48
        self._extra.append(tup)
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
    49
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    50
    def _fix_index(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    51
        if not isinstance(i, int):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    52
            raise TypeError("expecting int indexes")
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    53
        if i < 0:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    54
            i = len(self) + i
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    55
        if i < 0 or i >= len(self):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    56
            raise IndexError
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    57
        return i
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
    58
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    59
    def __getitem__(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    60
        i = self._fix_index(i)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    61
        if i == len(self) - 1:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    62
            return (0, 0, 0, -1, -1, -1, -1, nullid)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    63
        if i >= self._lgt:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    64
            return self._extra[i - self._lgt]
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    65
        index = self._calculate_index(i)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    66
        r = struct.unpack(indexformatng, self._data[index:index + indexsize])
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    67
        if i == 0:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    68
            e = list(r)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    69
            type = gettype(e[0])
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    70
            e[0] = offset_type(0, type)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    71
            return tuple(e)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    72
        return r
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    73
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    74
class IndexObject(BaseIndexObject):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    75
    def __init__(self, data):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    76
        assert len(data) % indexsize == 0
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    77
        self._data = data
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    78
        self._lgt = len(data) // indexsize
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    79
        self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    80
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    81
    def _calculate_index(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    82
        return i * indexsize
13253
61c9bc3da402 revlog: remove lazy index
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
    83
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    84
    def __delitem__(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    85
        if not isinstance(i, slice) or not i.stop == -1 or not i.step is None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    86
            raise ValueError("deleting slices only supports a:-1 with step 1")
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    87
        i = self._fix_index(i.start)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    88
        if i < self._lgt:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    89
            self._data = self._data[:i * indexsize]
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    90
            self._lgt = i
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    91
            self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    92
        else:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    93
            self._extra = self._extra[:i - self._lgt]
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    94
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    95
class InlinedIndexObject(BaseIndexObject):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    96
    def __init__(self, data, inline=0):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    97
        self._data = data
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    98
        self._lgt = self._inline_scan(None)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
    99
        self._inline_scan(self._lgt)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   100
        self._extra = []
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   101
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   102
    def _inline_scan(self, lgt):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   103
        off = 0
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   104
        if lgt is not None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   105
            self._offsets = [0] * lgt
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   106
        count = 0
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   107
        while off <= len(self._data) - indexsize:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   108
            s, = struct.unpack('>i',
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   109
                self._data[off + indexfirst:off + sizeint + indexfirst])
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   110
            if lgt is not None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   111
                self._offsets[count] = off
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   112
            count += 1
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   113
            off += indexsize + s
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   114
        if off != len(self._data):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   115
            raise ValueError("corrupted data")
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   116
        return count
14421
639f26cab2f5 pure parsers: properly detect corrupt index files
Augie Fackler <durin42@gmail.com>
parents: 14064
diff changeset
   117
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   118
    def __delitem__(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   119
        if not isinstance(i, slice) or not i.stop == -1 or not i.step is None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   120
            raise ValueError("deleting slices only supports a:-1 with step 1")
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   121
        i = self._fix_index(i.start)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   122
        if i < self._lgt:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   123
            self._offsets = self._offsets[:i]
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   124
            self._lgt = i
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   125
            self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   126
        else:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   127
            self._extra = self._extra[:i - self._lgt]
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   128
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   129
    def _calculate_index(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   130
        return self._offsets[i]
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   131
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   132
def parse_index2(data, inline):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   133
    if not inline:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   134
        return IndexObject(data), None
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   135
    return InlinedIndexObject(data, inline), (0, data)
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   136
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   137
def parse_dirstate(dmap, copymap, st):
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   138
    parents = [st[:20], st[20: 40]]
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 14995
diff changeset
   139
    # dereference fields so they will be local in loop
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   140
    format = ">cllll"
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   141
    e_size = struct.calcsize(format)
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   142
    pos1 = 40
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   143
    l = len(st)
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   144
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   145
    # the inner loop
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   146
    while pos1 < l:
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   147
        pos2 = pos1 + e_size
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   148
        e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   149
        pos1 = pos2 + e[4]
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   150
        f = st[pos2:pos1]
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   151
        if '\0' in f:
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   152
            f, c = f.split('\0')
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   153
            copymap[f] = c
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   154
        dmap[f] = e[:4]
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   155
    return parents
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   156
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   157
def pack_dirstate(dmap, copymap, pl, now):
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   158
    now = int(now)
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 27339
diff changeset
   159
    cs = stringio()
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   160
    write = cs.write
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   161
    write("".join(pl))
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   162
    for f, e in dmap.iteritems():
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   163
        if e[0] == 'n' and e[3] == now:
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   164
            # The file was last modified "simultaneously" with the current
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   165
            # write to dirstate (i.e. within the same second for file-
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   166
            # systems with a granularity of 1 sec). This commonly happens
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   167
            # for at least a couple of files on 'update'.
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   168
            # The user could change the file without changing its size
19652
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   169
            # within the same second. Invalidate the file's mtime in
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   170
            # dirstate, forcing future 'status' calls to compare the
19652
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   171
            # contents of the file if the size is the same. This prevents
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   172
            # mistakenly treating such files as clean.
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19652
diff changeset
   173
            e = dirstatetuple(e[0], e[1], e[2], -1)
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   174
            dmap[f] = e
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   175
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   176
        if f in copymap:
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   177
            f = "%s\0%s" % (f, copymap[f])
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   178
        e = _pack(">cllll", e[0], e[1], e[2], e[3], len(f))
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   179
        write(e)
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   180
        write(f)
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   181
    return cs.getvalue()