##// END OF EJS Templates
dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal -
r18567:194e63c1 default
parent child Browse files
Show More
@@ -9,10 +9,8 b' import errno'
9 9 from node import nullid
10 10 from i18n import _
11 11 import scmutil, util, ignore, osutil, parsers, encoding
12 import struct, os, stat, errno
13 import cStringIO
12 import os, stat, errno
14 13
15 _format = ">cllll"
16 14 propertycache = util.propertycache
17 15 filecache = scmutil.filecache
18 16 _rangemask = 0x7fffffff
@@ -508,38 +506,7 b' class dirstate(object):'
508 506 # use the modification time of the newly created temporary file as the
509 507 # filesystem's notion of 'now'
510 508 now = util.fstat(st).st_mtime
511 copymap = self._copymap
512 try:
513 finish(parsers.pack_dirstate(self._map, copymap, self._pl, now))
514 return
515 except AttributeError:
516 pass
517
518 now = int(now)
519 cs = cStringIO.StringIO()
520 pack = struct.pack
521 write = cs.write
522 write("".join(self._pl))
523 for f, e in self._map.iteritems():
524 if e[0] == 'n' and e[3] == now:
525 # The file was last modified "simultaneously" with the current
526 # write to dirstate (i.e. within the same second for file-
527 # systems with a granularity of 1 sec). This commonly happens
528 # for at least a couple of files on 'update'.
529 # The user could change the file without changing its size
530 # within the same second. Invalidate the file's stat data in
531 # dirstate, forcing future 'status' calls to compare the
532 # contents of the file. This prevents mistakenly treating such
533 # files as clean.
534 e = (e[0], 0, -1, -1) # mark entry as 'unset'
535 self._map[f] = e
536
537 if f in copymap:
538 f = "%s\0%s" % (f, copymap[f])
539 e = pack(_format, e[0], e[1], e[2], e[3], len(f))
540 write(e)
541 write(f)
542 finish(cs.getvalue())
509 finish(parsers.pack_dirstate(self._map, self._copymap, self._pl, now))
543 510
544 511 def _dirignore(self, f):
545 512 if f == '.':
@@ -326,7 +326,8 b' static PyObject *pack_dirstate(PyObject '
326 326 if (getintat(v, 3, &mtime) == -1)
327 327 goto bail;
328 328 if (*s == 'n' && mtime == (uint32_t)now) {
329 /* See dirstate.py:write for why we do this. */
329 /* See pure/parsers.py:pack_dirstate for why we do
330 * this. */
330 331 if (PyDict_SetItem(map, k, dirstate_unset) == -1)
331 332 goto bail;
332 333 mode = 0, size = -1, mtime = -1;
@@ -7,7 +7,7 b''
7 7
8 8 from mercurial.node import bin, nullid
9 9 from mercurial import util
10 import struct, zlib
10 import struct, zlib, cStringIO
11 11
12 12 _pack = struct.pack
13 13 _unpack = struct.unpack
@@ -87,3 +87,29 b' def parse_dirstate(dmap, copymap, st):'
87 87 copymap[f] = c
88 88 dmap[f] = e[:4]
89 89 return parents
90
91 def pack_dirstate(dmap, copymap, pl, now):
92 now = int(now)
93 cs = cStringIO.StringIO()
94 write = cs.write
95 write("".join(pl))
96 for f, e in dmap.iteritems():
97 if e[0] == 'n' and e[3] == now:
98 # The file was last modified "simultaneously" with the current
99 # write to dirstate (i.e. within the same second for file-
100 # systems with a granularity of 1 sec). This commonly happens
101 # for at least a couple of files on 'update'.
102 # The user could change the file without changing its size
103 # within the same second. Invalidate the file's stat data in
104 # dirstate, forcing future 'status' calls to compare the
105 # contents of the file. This prevents mistakenly treating such
106 # files as clean.
107 e = (e[0], 0, -1, -1) # mark entry as 'unset'
108 dmap[f] = e
109
110 if f in copymap:
111 f = "%s\0%s" % (f, copymap[f])
112 e = _pack(">cllll", e[0], e[1], e[2], e[3], len(f))
113 write(e)
114 write(f)
115 return cs.getvalue()
General Comments 0
You need to be logged in to leave comments. Login now