author | Matt Mackall <mpm@selenic.com> |
Fri, 27 Jun 2008 18:28:45 -0500 | |
changeset 6762 | f67d1468ac50 |
parent 6756 | d56ceb82cddb |
child 6767 | 80605a8127e0 |
permissions | -rw-r--r-- |
1089 | 1 |
""" |
2 |
dirstate.py - working directory tracking for mercurial |
|
3 |
||
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
4 |
Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
1089 | 5 |
|
6 |
This software may be used and distributed according to the terms |
|
7 |
of the GNU General Public License, incorporated herein by reference. |
|
8 |
""" |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
9 |
|
6211
f89fd07fc51d
Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents:
6201
diff
changeset
|
10 |
from node import nullid |
3891 | 11 |
from i18n import _ |
6212 | 12 |
import struct, os, bisect, stat, strutil, util, errno, ignore |
6326
af3f26b6bba4
dirstate: ignore stat data for files that were updated too recently
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6298
diff
changeset
|
13 |
import cStringIO, osutil, sys |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
14 |
|
4610 | 15 |
_unknown = ('?', 0, 0, 0) |
16 |
_format = ">cllll" |
|
17 |
||
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1541
diff
changeset
|
18 |
class dirstate(object): |
2393
5083cba2a777
dirstate: refactor the dirstate binary format, remove magic numbers
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2063
diff
changeset
|
19 |
|
244 | 20 |
def __init__(self, opener, ui, root): |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
21 |
self._opener = opener |
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
22 |
self._root = root |
4903
81078e177266
dirstate: use True and false for _dirty
Matt Mackall <mpm@selenic.com>
parents:
4677
diff
changeset
|
23 |
self._dirty = False |
4965 | 24 |
self._dirtypl = False |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
25 |
self._ui = ui |
723 | 26 |
|
4603
0f6853c15606
dirstate: use getattr rather than lazyread
Matt Mackall <mpm@selenic.com>
parents:
4527
diff
changeset
|
27 |
def __getattr__(self, name): |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
28 |
if name == '_map': |
4615
9b00b73a5286
dirstate: hide some more internals
Matt Mackall <mpm@selenic.com>
parents:
4614
diff
changeset
|
29 |
self._read() |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
30 |
return self._map |
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
31 |
elif name == '_copymap': |
4615
9b00b73a5286
dirstate: hide some more internals
Matt Mackall <mpm@selenic.com>
parents:
4614
diff
changeset
|
32 |
self._read() |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
33 |
return self._copymap |
6677
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
34 |
elif name == '_foldmap': |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
35 |
_foldmap = {} |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
36 |
for name in self._map: |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
37 |
norm = os.path.normcase(os.path.normpath(name)) |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
38 |
_foldmap[norm] = name |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
39 |
self._foldmap = _foldmap |
9865e15febd0
Add a normalize() method to dirstate
Paul Moore <p.f.moore@gmail.com>
parents:
6675
diff
changeset
|
40 |
return self._foldmap |
4604
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
41 |
elif name == '_branch': |
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
42 |
try: |
4633
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4620
diff
changeset
|
43 |
self._branch = (self._opener("branch").read().strip() |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4620
diff
changeset
|
44 |
or "default") |
4604
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
45 |
except IOError: |
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
46 |
self._branch = "default" |
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
47 |
return self._branch |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
48 |
elif name == '_pl': |
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
49 |
self._pl = [nullid, nullid] |
4604
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
50 |
try: |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
51 |
st = self._opener("dirstate").read(40) |
4604
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
52 |
if len(st) == 40: |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
53 |
self._pl = st[:20], st[20:40] |
4604
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
54 |
except IOError, err: |
c867c11426ad
dirstate: lazify copymap, _branch, and _pl
Matt Mackall <mpm@selenic.com>
parents:
4603
diff
changeset
|
55 |
if err.errno != errno.ENOENT: raise |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
56 |
return self._pl |
4615
9b00b73a5286
dirstate: hide some more internals
Matt Mackall <mpm@selenic.com>
parents:
4614
diff
changeset
|
57 |
elif name == '_dirs': |
9b00b73a5286
dirstate: hide some more internals
Matt Mackall <mpm@selenic.com>
parents:
4614
diff
changeset
|
58 |
self._dirs = {} |
4614
a8be3c875988
dirstate: hide internal vars
Matt Mackall <mpm@selenic.com>
parents:
4613
diff
changeset
|
59 |
for f in self._map: |
5487
7a64931e2d76
Fix file-changed-to-dir and dir-to-file commits (issue660).
Maxim Dounin <mdounin@mdounin.ru>
parents: |