Mercurial > hg
annotate mercurial/scmutil.py @ 24725:ee751d47cf2c
vfs: add walk
To eliminate "path prefix" (= "the root of vfs") part from "dirpath"
yielded by "os.walk()" correctly, "path prefix" should have "os.sep"
at the end of own string, but it isn't easy to ensure it, because:
- examination by "path.endswith(os.sep)" isn't portable
Some problematic encodings use 0x5c (= "os.sep" on Windows) as the
tail byte of some multi-byte characters.
- "os.path.join(path, '')" isn't portable
With Python 2.7.9, this invocation doesn't add "os.sep" at the end
of UNC path (see issue4557 for detail).
Python 2.7.9 changed also behavior of "os.path.normpath()" (see *) and
"os.path.splitdrive()" for UNC path.
vfs root normpath splitdrive os.sep required
=============== ============== =================== ============
z:\ z:\ z: + \ no
z:\foo z:\foo z: + \foo yes
z:\foo\ z:\foo z: + \foo yes
[before Python 2.7.9]
\\foo\bar \\foo\bar '' + \\foo\bar yes
\\foo\bar\ \\foo\bar (*) '' + \\foo\bar yes
\\foo\bar\baz \\foo\bar\baz '' + \\foo\bar\baz yes
\\foo\bar\baz\ \\foo\bar\baz '' + \\foo\bar\baz yes
[Python 2.7.9]
\\foo\bar \\foo\bar \\foo\bar + '' yes
\\foo\bar\ \\foo\bar\ (*) \\foo\bar + \ no
\\foo\bar\baz \\foo\bar\baz \\foo\bar + \baz yes
\\foo\bar\baz\ \\foo\bar\baz \\foo\bar + \baz yes
If it is ensured that "normpath()"-ed vfs root is passed to
"splitdrive()", adding "os.sep" is required only when "path" part of
"splitdrive()" result isn't "os.sep" itself. This is just what
"pathutil.nameasprefix()" examines.
This patch applies "os.path.normpath()" on "self.join(None)"
explicitly, because it isn't ensured that vfs root is already
normalized: vfs itself is constructed with "realpath=False" (= avoid
normalizing in "vfs.__init__()") in many code paths.
This normalization should be much cheaper than subsequent file I/O for
directory traversal.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 11 Apr 2015 23:00:04 +0900 |
parents | 467a33142425 |
children | bef8b17443a3 |
rev | line source |
---|---|
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
1 # scmutil.py - Mercurial core utility functions |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
2 # |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
3 # Copyright Matt Mackall <mpm@selenic.com> |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
4 # |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
7 |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
8 from i18n import _ |
18466
ac0c12123743
log: remove any ancestors of nullrev (issue3772)
Sean Farley <sean.michael.farley@gmail.com>
parents:
18450
diff
changeset
|
9 from mercurial.node import nullrev |
24635
21e1ece30f8c
util: move dirs() and finddirs() from scmutil to util
Drew Gottlieb <drgott@google.com>
parents:
24628
diff
changeset
|
10 import util, error, osutil, revset, similar, encoding, phases |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
20006
diff
changeset
|
11 import pathutil |
14320 | 12 import match as matchmod |
24689
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
13 import os, errno, re, glob, tempfile, shutil, stat |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
14 |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
15 if os.name == 'nt': |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
16 import scmwindows as scmplatform |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
17 else: |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
18 import scmposix as scmplatform |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
19 |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
20 systemrcpath = scmplatform.systemrcpath |
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
21 userrcpath = scmplatform.userrcpath |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
22 |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
23 class status(tuple): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
24 '''Named tuple with a list of files per status. The 'deleted', 'unknown' |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
25 and 'ignored' properties are only relevant to the working copy. |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
26 ''' |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
27 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
28 __slots__ = () |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
29 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
30 def __new__(cls, modified, added, removed, deleted, unknown, ignored, |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
31 clean): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
32 return tuple.__new__(cls, (modified, added, removed, deleted, unknown, |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
33 ignored, clean)) |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
34 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
35 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
36 def modified(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
37 '''files that have been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
38 return self[0] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
39 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
40 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
41 def added(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
42 '''files that have been added''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
43 return self[1] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
44 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
45 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
46 def removed(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
47 '''files that have been removed''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
48 return self[2] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
49 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
50 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
51 def deleted(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
52 '''files that are in the dirstate, but have been deleted from the |
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
53 working copy (aka "missing") |
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
54 ''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
55 return self[3] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
56 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
57 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
58 def unknown(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
59 '''files not in the dirstate that are not ignored''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
60 return self[4] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
61 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
62 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
63 def ignored(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
64 '''files not in the dirstate that are ignored (by _dirignore())''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
65 return self[5] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
66 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
67 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
68 def clean(self): |
22915
4d680deb0d9e
status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22913
diff
changeset
|
69 '''files that have not been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
70 return self[6] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
71 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
72 def __repr__(self, *args, **kwargs): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
73 return (('<status modified=%r, added=%r, removed=%r, deleted=%r, ' |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
74 'unknown=%r, ignored=%r, clean=%r>') % self) |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
75 |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
76 def itersubrepos(ctx1, ctx2): |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
77 """find subrepos in ctx1 or ctx2""" |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
78 # Create a (subpath, ctx) mapping where we prefer subpaths from |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
79 # ctx1. The subpaths from ctx2 are important when the .hgsub file |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
80 # has been modified (in ctx2) but not yet committed (in ctx1). |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
81 subpaths = dict.fromkeys(ctx2.substate, ctx2) |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
82 subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
83 for subpath, ctx in sorted(subpaths.iteritems()): |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
84 yield subpath, ctx.sub(subpath) |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
85 |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
86 def nochangesfound(ui, repo, excluded=None): |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
87 '''Report no changes for push/pull, excluded is None or a list of |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
88 nodes excluded from the push/pull. |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
89 ''' |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
90 secretlist = [] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
91 if excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
92 for n in excluded: |
18617
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
93 if n not in repo: |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
94 # discovery should not have included the filtered revision, |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
95 # we have to explicitly exclude it until discovery is cleanup. |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
96 continue |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
97 ctx = repo[n] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
98 if ctx.phase() >= phases.secret and not ctx.extinct(): |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
99 secretlist.append(n) |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
100 |
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
101 if secretlist: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
102 ui.status(_("no changes found (ignored %d secret changesets)\n") |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
103 % len(secretlist)) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
104 else: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
105 ui.status(_("no changes found\n")) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
106 |
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
107 def checknewlabel(repo, lbl, kind): |
19070
290a61833b99
translations: change label integer error to not specify the kind of label
Durham Goode <durham@fb.com>
parents:
18951
diff
changeset
|
108 # Do not use the "kind" parameter in ui output. |
290a61833b99
translations: change label integer error to not specify the kind of label
Durham Goode <durham@fb.com>
parents:
18951
diff
changeset
|
109 # It makes strings difficult to translate. |
17817
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
110 if lbl in ['tip', '.', 'null']: |
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
111 raise util.Abort(_("the name '%s' is reserved") % lbl) |
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
112 for c in (':', '\0', '\n', '\r'): |
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
113 if c in lbl: |
17850
71c1513fd560
scmutil: generalize message to make it more i18n-friendly
Wagner Bruna <wbruna@yahoo.com>
parents:
17846
diff
changeset
|
114 raise util.Abort(_("%r cannot be used in a name") % c) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
115 try: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
116 int(lbl) |
19070
290a61833b99
translations: change label integer error to not specify the kind of label
Durham Goode <durham@fb.com>
parents:
18951
diff
changeset
|
117 raise util.Abort(_("cannot use an integer as a name")) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
118 except ValueError: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
119 pass |
17817
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
120 |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
121 def checkfilename(f): |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
122 '''Check that the filename f is an acceptable filename for a tracked file''' |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
123 if '\r' in f or '\n' in f: |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
124 raise util.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f) |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
125 |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
126 def checkportable(ui, f): |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
127 '''Check if filename f is portable and warn or abort depending on config''' |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
128 checkfilename(f) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
129 abort, warn = checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
130 if abort or warn: |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
131 msg = util.checkwinfilename(f) |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
132 if msg: |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
133 msg = "%s: %r" % (msg, f) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
134 if abort: |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
135 raise util.Abort(msg) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
136 ui.warn(_("warning: %s\n") % msg) |
14068
04ce8fa1015d
add: notify when adding a file that would cause a case-folding collision
Kevin Gessner <kevin@kevingessner.com>
parents:
14067
diff
changeset
|
137 |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
138 def checkportabilityalert(ui): |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
139 '''check if the user's config requests nothing, a warning, or abort for |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
140 non-portable filenames''' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
141 val = ui.config('ui', 'portablefilenames', 'warn') |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
142 lval = val.lower() |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
143 bval = util.parsebool(val) |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
144 abort = os.name == 'nt' or lval == 'abort' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
145 warn = bval or lval == 'warn' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
146 if bval is None and not (warn or abort or lval == 'ignore'): |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
147 raise error.ConfigError( |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
148 _("ui.portablefilenames value is invalid ('%s')") % val) |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
149 return abort, warn |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
150 |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
151 class casecollisionauditor(object): |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
152 def __init__(self, ui, abort, dirstate): |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
153 self._ui = ui |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
154 self._abort = abort |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
155 allfiles = '\0'.join(dirstate._map) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
156 self._loweredfiles = set(encoding.lower(allfiles).split('\0')) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
157 self._dirstate = dirstate |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
158 # The purpose of _newfiles is so that we don't complain about |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
159 # case collisions if someone were to call this object with the |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
160 # same filename twice. |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
161 self._newfiles = set() |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
162 |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
163 def __call__(self, f): |
20006
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
164 if f in self._newfiles: |
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
165 return |
14980
28e98a8b173d
i18n: use UTF-8 string to lower filename for case collision check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
14861
diff
changeset
|
166 fl = encoding.lower(f) |
20006
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
167 if fl in self._loweredfiles and f not in self._dirstate: |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
168 msg = _('possible case-folding collision for %s') % f |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
169 if self._abort: |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
170 raise util.Abort(msg) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
171 self._ui.warn(_("warning: %s\n") % msg) |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
172 self._loweredfiles.add(fl) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
173 self._newfiles.add(f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
174 |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
175 def filteredhash(repo, maxrev): |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
176 """build hash of filtered revisions in the current repoview. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
177 |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
178 Multiple caches perform up-to-date validation by checking that the |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
179 tiprev and tipnode stored in the cache file match the current repository. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
180 However, this is not sufficient for validating repoviews because the set |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
181 of revisions in the view may change without the repository tiprev and |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
182 tipnode changing. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
183 |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
184 This function hashes all the revs filtered from the view and returns |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
185 that SHA-1 digest. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
186 """ |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
187 cl = repo.changelog |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
188 if not cl.filteredrevs: |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
189 return None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
190 key = None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
191 revs = sorted(r for r in cl.filteredrevs if r <= maxrev) |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
192 if revs: |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
193 s = util.sha1() |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
194 for rev in revs: |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
195 s.update('%s;' % rev) |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
196 key = s.digest() |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
197 return key |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
198 |
17649
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
199 class abstractvfs(object): |
14089
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
200 """Abstract base class; cannot be instantiated""" |
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
201 |
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
202 def __init__(self, *args, **kwargs): |
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
203 '''Prevent instantiation; don't call this from subclasses.''' |
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
204 raise NotImplementedError('attempted instantiating ' + str(type(self))) |
d3f7e110c3c0
opener: introduce an abstact superclass of it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14068
diff
changeset
|
205 |
16455
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
206 def tryread(self, path): |
16479
fc04698fa778
opener: coding style, use triple quotes for doc string
Thomas Arendsen Hein <thomas@intevation.de>
parents:
16455
diff
changeset
|
207 '''gracefully return an empty string for missing files''' |
16455
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
208 try: |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
209 return self.read(path) |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
210 except IOError, inst: |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
211 if inst.errno != errno.ENOENT: |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
212 raise |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
213 return "" |
154219f3a6a4
opener: introduce tryread helper
Matt Mackall <mpm@selenic.com>
parents:
16436
diff
changeset
|
214 |
23368
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
215 def tryreadlines(self, path, mode='rb'): |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
216 '''gracefully return an empty array for missing files''' |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
217 try: |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
218 return self.readlines(path, mode=mode) |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
219 except IOError, inst: |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
220 if inst.errno != errno.ENOENT: |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
221 raise |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
222 return [] |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
223 |
23370
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
224 def open(self, path, mode="r", text=False, atomictemp=False, |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
225 notindexed=False): |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
226 '''Open ``path`` file, which is relative to vfs root. |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
227 |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
228 Newly created directories are marked as "not to be indexed by |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
229 the content indexing service", if ``notindexed`` is specified |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
230 for "write" mode access. |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
231 ''' |
19897
896a4568def7
vfs: add "open()" for newly added code paths which open files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19896
diff
changeset
|
232 self.open = self.__call__ |
23370
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
233 return self.__call__(path, mode, text, atomictemp, notindexed) |
19897
896a4568def7
vfs: add "open()" for newly added code paths which open files via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19896
diff
changeset
|
234 |
14167
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
235 def read(self, path): |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
236 fp = self(path, 'rb') |
14097
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
237 try: |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
238 return fp.read() |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
239 finally: |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
240 fp.close() |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
241 |
23368
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
242 def readlines(self, path, mode='rb'): |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
243 fp = self(path, mode=mode) |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
244 try: |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
245 return fp.readlines() |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
246 finally: |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
247 fp.close() |
bf8c3172255c
vfs: add "readlines" and "tryreadlines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23259
diff
changeset
|
248 |
14167
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
249 def write(self, path, data): |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
250 fp = self(path, 'wb') |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
251 try: |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
252 return fp.write(data) |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
253 finally: |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
254 fp.close() |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
255 |
23371
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
256 def writelines(self, path, data, mode='wb', notindexed=False): |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
257 fp = self(path, mode=mode, notindexed=notindexed) |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
258 try: |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
259 return fp.writelines(data) |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
260 finally: |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
261 fp.close() |
1df6519eb3ab
vfs: add "writelines"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23370
diff
changeset
|
262 |
14167
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
263 def append(self, path, data): |
0e4753807c93
util & scmutil: adapt read/write helpers as request by mpm
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14138
diff
changeset
|
264 fp = self(path, 'ab') |
14097
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
265 try: |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
266 return fp.write(data) |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
267 finally: |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
268 fp.close() |
ca3376f044f8
opener: add read & write utility methods
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14090
diff
changeset
|
269 |
20086
f3df2612f3c3
vfs: add "chmod()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20085
diff
changeset
|
270 def chmod(self, path, mode): |
f3df2612f3c3
vfs: add "chmod()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20085
diff
changeset
|
271 return os.chmod(self.join(path), mode) |
f3df2612f3c3
vfs: add "chmod()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20085
diff
changeset
|
272 |
17161
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
273 def exists(self, path=None): |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
274 return os.path.exists(self.join(path)) |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
275 |
19899
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19897
diff
changeset
|
276 def fstat(self, fp): |
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19897
diff
changeset
|
277 return util.fstat(fp) |
8c3dcbbfb5de
changelog: use "vfs.fstat()" instead of "util.fstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19897
diff
changeset
|
278 |
17161
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
279 def isdir(self, path=None): |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
280 return os.path.isdir(self.join(path)) |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
281 |
20085
589d6bb5b18d
vfs: add "isfile()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20045
diff
changeset
|
282 def isfile(self, path=None): |
589d6bb5b18d
vfs: add "isfile()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20045
diff
changeset
|
283 return os.path.isfile(self.join(path)) |
589d6bb5b18d
vfs: add "isfile()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20045
diff
changeset
|
284 |
18949
138978f20180
localrepo: use "vfs.islink()" instead of "os.path.islink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18948
diff
changeset
|
285 def islink(self, path=None): |
138978f20180
localrepo: use "vfs.islink()" instead of "os.path.islink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18948
diff
changeset
|
286 return os.path.islink(self.join(path)) |
138978f20180
localrepo: use "vfs.islink()" instead of "os.path.islink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18948
diff
changeset
|
287 |
23581
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
288 def reljoin(self, *paths): |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
289 """join various elements of a path together (as os.path.join would do) |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
290 |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
291 The vfs base is not injected so that path stay relative. This exists |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
292 to allow handling of strange encoding if needed.""" |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
293 return os.path.join(*paths) |
aed981c7bebf
vfs: add a 'reljoin' function for joining relative paths
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23539
diff
changeset
|
294 |
23582
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
295 def split(self, path): |
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
296 """split top-most element of a path (as os.path.split would do) |
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
297 |
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
298 This exists to allow handling of strange encoding if needed.""" |
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
299 return os.path.split(path) |
7559dc8c4238
vfs: add a 'split' method
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23581
diff
changeset
|
300 |
21563
764b691b8bda
vfs: add lexists() in current api
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21111
diff
changeset
|
301 def lexists(self, path=None): |
764b691b8bda
vfs: add lexists() in current api
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21111
diff
changeset
|
302 return os.path.lexists(self.join(path)) |
764b691b8bda
vfs: add lexists() in current api
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21111
diff
changeset
|
303 |
19900
7c21e3398931
context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19899
diff
changeset
|
304 def lstat(self, path=None): |
7c21e3398931
context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19899
diff
changeset
|
305 return os.lstat(self.join(path)) |
7c21e3398931
context: use "vfs.lstat()" instead of "os.lstat()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19899
diff
changeset
|
306 |
21799
dfacdd6a111e
vfs: add listdir for os.listdir in vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21716
diff
changeset
|
307 def listdir(self, path=None): |
dfacdd6a111e
vfs: add listdir for os.listdir in vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21716
diff
changeset
|
308 return os.listdir(self.join(path)) |
dfacdd6a111e
vfs: add listdir for os.listdir in vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21716
diff
changeset
|
309 |
17161
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
310 def makedir(self, path=None, notindexed=True): |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
311 return util.makedir(self.join(path), notindexed) |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
312 |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
313 def makedirs(self, path=None, mode=None): |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
314 return util.makedirs(self.join(path), mode) |
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
315 |
20090
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
316 def makelock(self, info, path): |
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
317 return util.makelock(info, self.join(path)) |
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
318 |
17723
ab23768746fd
scmutil: reorder newly added functions for vfs support in dictionary order
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17681
diff
changeset
|
319 def mkdir(self, path=None): |
ab23768746fd
scmutil: reorder newly added functions for vfs support in dictionary order
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17681
diff
changeset
|
320 return os.mkdir(self.join(path)) |
ab23768746fd
scmutil: reorder newly added functions for vfs support in dictionary order
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17681
diff
changeset
|
321 |
20980
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
322 def mkstemp(self, suffix='', prefix='tmp', dir=None, text=False): |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
323 fd, name = tempfile.mkstemp(suffix=suffix, prefix=prefix, |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
324 dir=self.join(dir), text=text) |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
325 dname, fname = util.split(name) |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
326 if dir: |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
327 return fd, os.path.join(dir, fname) |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
328 else: |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
329 return fd, fname |
6fb4c94ae300
vfs: add "mkstemp()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20862
diff
changeset
|
330 |
17747
aad3bce98f76
store: invoke "osutil.listdir()" via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17726
diff
changeset
|
331 def readdir(self, path=None, stat=None, skip=None): |
aad3bce98f76
store: invoke "osutil.listdir()" via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17726
diff
changeset
|
332 return osutil.listdir(self.join(path), stat, skip) |
aad3bce98f76
store: invoke "osutil.listdir()" via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17726
diff
changeset
|
333 |
20090
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
334 def readlock(self, path): |
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
335 return util.readlock(self.join(path)) |
88d8e568add1
vfs: add "makelock()" and "readlock()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20086
diff
changeset
|
336 |
18948
2f05fa162316
localrepo: use "vfs.rename()" instead of "util.rename()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18945
diff
changeset
|
337 def rename(self, src, dst): |
2f05fa162316
localrepo: use "vfs.rename()" instead of "util.rename()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18945
diff
changeset
|
338 return util.rename(self.join(src), self.join(dst)) |
2f05fa162316
localrepo: use "vfs.rename()" instead of "util.rename()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18945
diff
changeset
|
339 |
18950
647e3b0c8751
localrepo: use "vfs.readlink()" instead of "os.readlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18949
diff
changeset
|
340 def readlink(self, path): |
647e3b0c8751
localrepo: use "vfs.readlink()" instead of "os.readlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18949
diff
changeset
|
341 return os.readlink(self.join(path)) |
647e3b0c8751
localrepo: use "vfs.readlink()" instead of "os.readlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18949
diff
changeset
|
342 |
24693
0d28b0df77ea
vfs: add removedirs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24689
diff
changeset
|
343 def removedirs(self, path=None): |
0d28b0df77ea
vfs: add removedirs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24689
diff
changeset
|
344 """Remove a leaf directory and all empty intermediate ones |
0d28b0df77ea
vfs: add removedirs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24689
diff
changeset
|
345 """ |
0d28b0df77ea
vfs: add removedirs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24689
diff
changeset
|
346 return util.removedirs(self.join(path)) |
0d28b0df77ea
vfs: add removedirs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24689
diff
changeset
|
347 |
24689
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
348 def rmtree(self, path=None, ignore_errors=False, forcibly=False): |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
349 """Remove a directory tree recursively |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
350 |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
351 If ``forcibly``, this tries to remove READ-ONLY files, too. |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
352 """ |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
353 if forcibly: |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
354 def onerror(function, path, excinfo): |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
355 if function is not os.remove: |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
356 raise |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
357 # read-only files cannot be unlinked under Windows |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
358 s = os.stat(path) |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
359 if (s.st_mode & stat.S_IWRITE) != 0: |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
360 raise |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
361 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
362 os.remove(path) |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
363 else: |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
364 onerror = None |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
365 return shutil.rmtree(self.join(path), |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
366 ignore_errors=ignore_errors, onerror=onerror) |
ca3a90096c95
vfs: add rmtree
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24635
diff
changeset
|
367 |
18951
d13916a00b7e
localrepo: use "vfs.setflags()" instead of "util.setflags()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18950
diff
changeset
|
368 def setflags(self, path, l, x): |
d13916a00b7e
localrepo: use "vfs.setflags()" instead of "util.setflags()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18950
diff
changeset
|
369 return util.setflags(self.join(path), l, x) |
d13916a00b7e
localrepo: use "vfs.setflags()" instead of "util.setflags()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18950
diff
changeset
|
370 |
17726
7cb7e17c23b2
store: invoke "os.stat()" for "createmode" initialization via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17725
diff
changeset
|
371 def stat(self, path=None): |
7cb7e17c23b2
store: invoke "os.stat()" for "createmode" initialization via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17725
diff
changeset
|
372 return os.stat(self.join(path)) |
7cb7e17c23b2
store: invoke "os.stat()" for "createmode" initialization via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17725
diff
changeset
|
373 |
19895
37c0d93fb166
bookmarks: use "vfs.unlink()" instead of "util.unlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19655
diff
changeset
|
374 def unlink(self, path=None): |
37c0d93fb166
bookmarks: use "vfs.unlink()" instead of "util.unlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19655
diff
changeset
|
375 return util.unlink(self.join(path)) |
37c0d93fb166
bookmarks: use "vfs.unlink()" instead of "util.unlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19655
diff
changeset
|
376 |
21716
90f9be5adade
vfs: add unlinkpath to vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21563
diff
changeset
|
377 def unlinkpath(self, path=None, ignoremissing=False): |
90f9be5adade
vfs: add unlinkpath to vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21563
diff
changeset
|
378 return util.unlinkpath(self.join(path), ignoremissing) |
90f9be5adade
vfs: add unlinkpath to vfs
Chinmay Joshi <c@chinmayjoshi.com>
parents:
21563
diff
changeset
|
379 |
19896
af03279c766a
bookmarks: use "vfs.utime()" instead of "os.utime()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19895
diff
changeset
|
380 def utime(self, path=None, t=None): |
af03279c766a
bookmarks: use "vfs.utime()" instead of "os.utime()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19895
diff
changeset
|
381 return os.utime(self.join(path), t) |
af03279c766a
bookmarks: use "vfs.utime()" instead of "os.utime()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19895
diff
changeset
|
382 |
24725 | 383 def walk(self, path=None, onerror=None): |
384 """Yield (dirpath, dirs, files) tuple for each directories under path | |
385 | |
386 ``dirpath`` is relative one from the root of this vfs. This | |
387 uses ``os.sep`` as path separator, even you specify POSIX | |
388 style ``path``. | |
389 | |
390 "The root of this vfs" is represented as empty ``dirpath``. | |
391 """ | |
392 root = os.path.normpath(self.join(None)) | |
393 # when dirpath == root, dirpath[prefixlen:] becomes empty | |
394 # because len(dirpath) < prefixlen. | |
395 prefixlen = len(pathutil.normasprefix(root)) | |
396 for dirpath, dirs, files in os.walk(self.join(path), onerror=onerror): | |
397 yield (dirpath[prefixlen:], dirs, files) | |
398 | |
17649
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
399 class vfs(abstractvfs): |
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
400 '''Operate files relative to a base directory |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
401 |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
402 This class is used to hide the details of COW semantics and |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
403 remote file access from higher level code. |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
404 ''' |
18945
e75b72fffdfe
vfs: split "expand" into "realpath"/"expandpath" to apply each separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18900
diff
changeset
|
405 def __init__(self, base, audit=True, expandpath=False, realpath=False): |
e75b72fffdfe
vfs: split "expand" into "realpath"/"expandpath" to apply each separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18900
diff
changeset
|
406 if expandpath: |
e75b72fffdfe
vfs: split "expand" into "realpath"/"expandpath" to apply each separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18900
diff
changeset
|
407 base = util.expandpath(base) |
e75b72fffdfe
vfs: split "expand" into "realpath"/"expandpath" to apply each separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18900
diff
changeset
|
408 if realpath: |
e75b72fffdfe
vfs: split "expand" into "realpath"/"expandpath" to apply each separately
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18900
diff
changeset
|
409 base = os.path.realpath(base) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
410 self.base = base |
17554
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
411 self._setmustaudit(audit) |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
412 self.createmode = None |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
413 self._trustnlink = None |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
414 |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
415 def _getmustaudit(self): |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
416 return self._audit |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
417 |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
418 def _setmustaudit(self, onoff): |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
419 self._audit = onoff |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
420 if onoff: |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
20006
diff
changeset
|
421 self.audit = pathutil.pathauditor(self.base) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
422 else: |
18327
4aecdb91443c
scmutil: simplify vfs.audit - drop wrapped vfs.auditor
Mads Kiilerich <mads@kiilerich.com>
parents:
18316
diff
changeset
|
423 self.audit = util.always |
17554
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
424 |
5450c8ad9d98
scmutil: turn opener._audit into a property, mustaudit
Bryan O'Sullivan <bryano@fb.com>
parents:
17248
diff
changeset
|
425 mustaudit = property(_getmustaudit, _setmustaudit) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
426 |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
427 @util.propertycache |
14261
e3649bcca3f6
opener: rename _can_symlink to _cansymlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
428 def _cansymlink(self): |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
429 return util.checklink(self.base) |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
430 |
18192
f9a89bdd64a6
scmutil: don't try to match modes on filesystems without modes (issue3740)
Matt Mackall <mpm@selenic.com>
parents:
17850
diff
changeset
|
431 @util.propertycache |
f9a89bdd64a6
scmutil: don't try to match modes on filesystems without modes (issue3740)
Matt Mackall <mpm@selenic.com>
parents:
17850
diff
changeset
|
432 def _chmod(self): |
f9a89bdd64a6
scmutil: don't try to match modes on filesystems without modes (issue3740)
Matt Mackall <mpm@selenic.com>
parents:
17850
diff
changeset
|
433 return util.checkexec(self.base) |
f9a89bdd64a6
scmutil: don't try to match modes on filesystems without modes (issue3740)
Matt Mackall <mpm@selenic.com>
parents:
17850
diff
changeset
|
434 |
17763
13070de77c86
vfs: backout fchmod change from 76b73ce0ffac
Matt Mackall <mpm@selenic.com>
parents:
17752
diff
changeset
|
435 def _fixfilemode(self, name): |
18192
f9a89bdd64a6
scmutil: don't try to match modes on filesystems without modes (issue3740)
Matt Mackall <mpm@selenic.com>
parents:
17850
diff
changeset
|
436 if self.createmode is None or not self._chmod: |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
437 return |
17763
13070de77c86
vfs: backout fchmod change from 76b73ce0ffac
Matt Mackall <mpm@selenic.com>
parents:
17752
diff
changeset
|
438 os.chmod(name, self.createmode & 0666) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
439 |
23370
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
440 def __call__(self, path, mode="r", text=False, atomictemp=False, |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
441 notindexed=False): |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
442 '''Open ``path`` file, which is relative to vfs root. |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
443 |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
444 Newly created directories are marked as "not to be indexed by |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
445 the content indexing service", if ``notindexed`` is specified |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
446 for "write" mode access. |
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
447 ''' |
14720
36283a7b6856
opener: add self._audit (issue2862)
Adrian Buehlmann <adrian@cadifra.com>
parents:
14672
diff
changeset
|
448 if self._audit: |
36283a7b6856
opener: add self._audit (issue2862)
Adrian Buehlmann <adrian@cadifra.com>
parents:
14672
diff
changeset
|
449 r = util.checkosfilename(path) |
36283a7b6856
opener: add self._audit (issue2862)
Adrian Buehlmann <adrian@cadifra.com>
parents:
14672
diff
changeset
|
450 if r: |
36283a7b6856
opener: add self._audit (issue2862)
Adrian Buehlmann <adrian@cadifra.com>
parents:
14672
diff
changeset
|
451 raise util.Abort("%s: %r" % (r, path)) |
18327
4aecdb91443c
scmutil: simplify vfs.audit - drop wrapped vfs.auditor
Mads Kiilerich <mads@kiilerich.com>
parents:
18316
diff
changeset
|
452 self.audit(path) |
16199
8181bd808dc5
scmutil: add join method to opener to construct path relative to base
Idan Kamara <idankk86@gmail.com>
parents:
16198
diff
changeset
|
453 f = self.join(path) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
454 |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
455 if not text and "b" not in mode: |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
456 mode += "b" # for that other OS |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
457 |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
458 nlink = -1 |
17937
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
459 if mode not in ('r', 'rb'): |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
460 dirname, basename = util.split(f) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
461 # If basename is empty, then the path is malformed because it points |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
462 # to a directory. Let the posixfile() call below raise IOError. |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
463 if basename: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
464 if atomictemp: |
23370
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
465 util.ensuredirs(dirname, self.createmode, notindexed) |
17937
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
466 return util.atomictempfile(f, mode, self.createmode) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
467 try: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
468 if 'w' in mode: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
469 util.unlink(f) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
470 nlink = 0 |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
471 else: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
472 # nlinks() may behave differently for files on Windows |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
473 # shares if the file is open. |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
474 fd = util.posixfile(f) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
475 nlink = util.nlinks(f) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
476 if nlink < 1: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
477 nlink = 2 # force mktempcopy (issue1922) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
478 fd.close() |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
479 except (OSError, IOError), e: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
480 if e.errno != errno.ENOENT: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
481 raise |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
482 nlink = 0 |
23370
46265d0f0c7b
vfs: add "notindexed" argument to invoke "ensuredir" with it in write mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23368
diff
changeset
|
483 util.ensuredirs(dirname, self.createmode, notindexed) |
17937
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
484 if nlink > 0: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
485 if self._trustnlink is None: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
486 self._trustnlink = nlink > 1 or util.checknlink(f) |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
487 if nlink > 1 or not self._trustnlink: |
3cb032d50447
vfs: optimize __call__ by not calling util.split for reads
Adrian Buehlmann <adrian@cadifra.com>
parents:
17850
diff
changeset
|
488 util.rename(util.mktempcopy(f), f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
489 fp = util.posixfile(f, mode) |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
490 if nlink == 0: |
17763
13070de77c86
vfs: backout fchmod change from 76b73ce0ffac
Matt Mackall <mpm@selenic.com>
parents:
17752
diff
changeset
|
491 self._fixfilemode(f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
492 return fp |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
493 |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
494 def symlink(self, src, dst): |
18327
4aecdb91443c
scmutil: simplify vfs.audit - drop wrapped vfs.auditor
Mads Kiilerich <mads@kiilerich.com>
parents:
18316
diff
changeset
|
495 self.audit(dst) |
16199
8181bd808dc5
scmutil: add join method to opener to construct path relative to base
Idan Kamara <idankk86@gmail.com>
parents:
16198
diff
changeset
|
496 linkname = self.join(dst) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
497 try: |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
498 os.unlink(linkname) |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
499 except OSError: |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
500 pass |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
501 |
18678
423eee0b0b14
util: make ensuredirs safer against races
Bryan O'Sullivan <bryano@fb.com>
parents:
18668
diff
changeset
|
502 util.ensuredirs(os.path.dirname(linkname), self.createmode) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
503 |
14261
e3649bcca3f6
opener: rename _can_symlink to _cansymlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
504 if self._cansymlink: |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
505 try: |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
506 os.symlink(src, linkname) |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
507 except OSError, err: |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
508 raise OSError(err.errno, _('could not symlink to %r: %s') % |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
509 (src, err.strerror), linkname) |
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
510 else: |
17768
9837cafc25b1
vfs: use self.write to write symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
17763
diff
changeset
|
511 self.write(dst, src) |
13971
bfeaa88b875d
move canonpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13970
diff
changeset
|
512 |
24628
a0b47885a1c5
vfs: make it possible to pass multiple path elements to join
Matt Harbison <matt_harbison@yahoo.com>
parents:
24582
diff
changeset
|
513 def join(self, path, *insidef): |
17161
be016e96117a
localrepo: use file API via vfs while ensuring repository directory
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17157
diff
changeset
|
514 if path: |
24628
a0b47885a1c5
vfs: make it possible to pass multiple path elements to join
Matt Harbison <matt_harbison@yahoo.com>
parents:
24582
diff
changeset
|
515 return os.path.join(self.base, path, *insidef) |
17681
a41fd730f230
scmutil: backout 83785bb56062 (issue3643)
Matt Mackall <mpm@selenic.com>
parents:
17675
diff
changeset
|
516 else: |
a41fd730f230
scmutil: backout 83785bb56062 (issue3643)
Matt Mackall <mpm@selenic.com>
parents:
17675
diff
changeset
|
517 return self.base |
16199
8181bd808dc5
scmutil: add join method to opener to construct path relative to base
Idan Kamara <idankk86@gmail.com>
parents:
16198
diff
changeset
|
518 |
17649
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
519 opener = vfs |
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
520 |
17845
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
521 class auditvfs(object): |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
522 def __init__(self, vfs): |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
523 self.vfs = vfs |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
524 |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
525 def _getmustaudit(self): |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
526 return self.vfs.mustaudit |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
527 |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
528 def _setmustaudit(self, onoff): |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
529 self.vfs.mustaudit = onoff |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
530 |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
531 mustaudit = property(_getmustaudit, _setmustaudit) |
408ded42c5ec
scmutil: abstract out mustaudit delegation
Bryan O'Sullivan <bryano@fb.com>
parents:
17821
diff
changeset
|
532 |
17846
f42cf30873dc
scmutil: add mustaudit delegation to filtervfs (issue3673)
Bryan O'Sullivan <bryano@fb.com>
parents:
17845
diff
changeset
|
533 class filtervfs(abstractvfs, auditvfs): |
17649
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
534 '''Wrapper vfs for filtering filenames with a function.''' |
14090
e24b5e3c2f27
add filteropener abstraction for store openers
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14089
diff
changeset
|
535 |
17846
f42cf30873dc
scmutil: add mustaudit delegation to filtervfs (issue3673)
Bryan O'Sullivan <bryano@fb.com>
parents:
17845
diff
changeset
|
536 def __init__(self, vfs, filter): |
f42cf30873dc
scmutil: add mustaudit delegation to filtervfs (issue3673)
Bryan O'Sullivan <bryano@fb.com>
parents:
17845
diff
changeset
|
537 auditvfs.__init__(self, vfs) |
14090
e24b5e3c2f27
add filteropener abstraction for store openers
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14089
diff
changeset
|
538 self._filter = filter |
e24b5e3c2f27
add filteropener abstraction for store openers
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14089
diff
changeset
|
539 |
e24b5e3c2f27
add filteropener abstraction for store openers
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14089
diff
changeset
|
540 def __call__(self, path, *args, **kwargs): |
17846
f42cf30873dc
scmutil: add mustaudit delegation to filtervfs (issue3673)
Bryan O'Sullivan <bryano@fb.com>
parents:
17845
diff
changeset
|
541 return self.vfs(self._filter(path), *args, **kwargs) |
14090
e24b5e3c2f27
add filteropener abstraction for store openers
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14089
diff
changeset
|
542 |
24628
a0b47885a1c5
vfs: make it possible to pass multiple path elements to join
Matt Harbison <matt_harbison@yahoo.com>
parents:
24582
diff
changeset
|
543 def join(self, path, *insidef): |
17725
ffd589d4b785
vfs: define "join()" in each classes derived from "abstractvfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17723
diff
changeset
|
544 if path: |
24628
a0b47885a1c5
vfs: make it possible to pass multiple path elements to join
Matt Harbison <matt_harbison@yahoo.com>
parents:
24582
diff
changeset
|
545 return self.vfs.join(self._filter(self.vfs.reljoin(path, *insidef))) |
17725
ffd589d4b785
vfs: define "join()" in each classes derived from "abstractvfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17723
diff
changeset
|
546 else: |
17846
f42cf30873dc
scmutil: add mustaudit delegation to filtervfs (issue3673)
Bryan O'Sullivan <bryano@fb.com>
parents:
17845
diff
changeset
|
547 return self.vfs.join(path) |
17725
ffd589d4b785
vfs: define "join()" in each classes derived from "abstractvfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17723
diff
changeset
|
548 |
17649
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
549 filteropener = filtervfs |
f65c6a5f256c
scmutil: rename classes from "opener" to "vfs"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17561
diff
changeset
|
550 |
18213
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
551 class readonlyvfs(abstractvfs, auditvfs): |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
552 '''Wrapper vfs preventing any writing.''' |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
553 |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
554 def __init__(self, vfs): |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
555 auditvfs.__init__(self, vfs) |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
556 |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
557 def __call__(self, path, mode='r', *args, **kw): |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
558 if mode not in ('r', 'rb'): |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
559 raise util.Abort('this vfs is read only') |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
560 return self.vfs(path, mode, *args, **kw) |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
561 |
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
562 |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
563 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): |
17104
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
17037
diff
changeset
|
564 '''yield every hg repository under path, always recursively. |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
17037
diff
changeset
|
565 The recurse flag will only control recursion into repo working dirs''' |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
566 def errhandler(err): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
567 if err.filename == path: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
568 raise err |
14961
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
569 samestat = getattr(os.path, 'samestat', None) |
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
570 if followsym and samestat is not None: |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
571 def adddir(dirlst, dirname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
572 match = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
573 dirstat = os.stat(dirname) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
574 for lstdirstat in dirlst: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
575 if samestat(dirstat, lstdirstat): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
576 match = True |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
577 break |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
578 if not match: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
579 dirlst.append(dirstat) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
580 return not match |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
581 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
582 followsym = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
583 |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
584 if (seen_dirs is None) and followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
585 seen_dirs = [] |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
586 adddir(seen_dirs, path) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
587 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
588 dirs.sort() |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
589 if '.hg' in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
590 yield root # found a repository |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
591 qroot = os.path.join(root, '.hg', 'patches') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
592 if os.path.isdir(os.path.join(qroot, '.hg')): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
593 yield qroot # we have a patch queue repo here |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
594 if recurse: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
595 # avoid recursing inside the .hg directory |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
596 dirs.remove('.hg') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
597 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
598 dirs[:] = [] # don't descend further |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
599 elif followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
600 newdirs = [] |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
601 for d in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
602 fname = os.path.join(root, d) |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
603 if adddir(seen_dirs, fname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
604 if os.path.islink(fname): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
605 for hgname in walkrepos(fname, True, seen_dirs): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
606 yield hgname |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
607 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
608 newdirs.append(d) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
609 dirs[:] = newdirs |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
610 |
14224
f4189866c76c
rename scmutil.os_rcpath to osrcpath
Adrian Buehlmann <adrian@cadifra.com>
parents:
14220
diff
changeset
|
611 def osrcpath(): |
13985
26335a817dd0
move os_rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13984
diff
changeset
|
612 '''return default os-specific hgrc search path''' |
23142
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
613 path = [] |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
614 defaultpath = os.path.join(util.datapath, 'default.d') |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
615 if os.path.isdir(defaultpath): |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
616 for f, kind in osutil.listdir(defaultpath): |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
617 if f.endswith('.rc'): |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
618 path.append(os.path.join(defaultpath, f)) |
c4ce077588d0
config: introduce "built-in" default configuration settings in default.d
Mads Kiilerich <madski@unity3d.com>
parents:
22915
diff
changeset
|
619 path.extend(systemrcpath()) |
14226
73cca883370d
rename scmutil.user_rcpath to userrcpath
Adrian Buehlmann <adrian@cadifra.com>
parents:
14225
diff
changeset
|
620 path.extend(userrcpath()) |
13985
26335a817dd0
move os_rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13984
diff
changeset
|
621 path = [os.path.normpath(f) for f in path] |
26335a817dd0
move os_rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13984
diff
changeset
|
622 return path |
26335a817dd0
move os_rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13984
diff
changeset
|
623 |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
624 _rcpath = None |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
625 |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
626 def rcpath(): |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
627 '''return hgrc search path. if env var HGRCPATH is set, use it. |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
628 for each item in path, if directory, use files ending in .rc, |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
629 else use item. |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
630 make HGRCPATH empty to only look in .hg/hgrc of current repo. |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
631 if no HGRCPATH, use default os-specific path.''' |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
632 global _rcpath |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
633 if _rcpath is None: |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
634 if 'HGRCPATH' in os.environ: |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
635 _rcpath = [] |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
636 for p in os.environ['HGRCPATH'].split(os.pathsep): |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
637 if not p: |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
638 continue |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
639 p = util.expandpath(p) |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
640 if os.path.isdir(p): |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
641 for f, kind in osutil.listdir(p): |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
642 if f.endswith('.rc'): |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
643 _rcpath.append(os.path.join(p, f)) |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
644 else: |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
645 _rcpath.append(p) |
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
646 else: |
14224
f4189866c76c
rename scmutil.os_rcpath to osrcpath
Adrian Buehlmann <adrian@cadifra.com>
parents:
14220
diff
changeset
|
647 _rcpath = osrcpath() |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
648 return _rcpath |
13986
9c374cf76b7d
move system_rcpath and user_rcpath to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13985
diff
changeset
|
649 |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
650 def intrev(repo, rev): |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
651 """Return integer for a given revision that can be used in comparison or |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
652 arithmetic operation""" |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
653 if rev is None: |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
654 return len(repo) |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
655 return rev |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
656 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
657 def revsingle(repo, revspec, default='.'): |
19509
8963a706e075
revsingle: fix silly API issue (issue2992)
Matt Mackall <mpm@selenic.com>
parents:
19154
diff
changeset
|
658 if not revspec and revspec != 0: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
659 return repo[default] |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
660 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
661 l = revrange(repo, [revspec]) |
22814
8110405cf8ae
revset-limit: use boolean testing instead of `len(revs) < 1`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21799
diff
changeset
|
662 if not l: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
663 raise util.Abort(_('empty revision set')) |
22815
4f81470e83bf
revsingle: use `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22814
diff
changeset
|
664 return repo[l.last()] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
665 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
666 def revpair(repo, revs): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
667 if not revs: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
668 return repo.dirstate.p1(), None |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
669 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
670 l = revrange(repo, revs) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
671 |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
672 if not l: |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
673 first = second = None |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
674 elif l.isascending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
675 first = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
676 second = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
677 elif l.isdescending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
678 first = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
679 second = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
680 else: |
22816
20d998395ee7
revpair: use `first` and `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22815
diff
changeset
|
681 first = l.first() |
20d998395ee7
revpair: use `first` and `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22815
diff
changeset
|
682 second = l.last() |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
683 |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
684 if first is None: |
20819
202291a280fb
revpair: drop useless conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20798
diff
changeset
|
685 raise util.Abort(_('empty revision range')) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
686 |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
687 if first == second and len(revs) == 1 and _revrangesep not in revs[0]: |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
688 return repo.lookup(first), None |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
689 |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
690 return repo.lookup(first), repo.lookup(second) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
691 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
692 _revrangesep = ':' |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
693 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
694 def revrange(repo, revs): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
695 """Yield revision as strings from a list of revision specifications.""" |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
696 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
697 def revfix(repo, val, defval): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
698 if not val and val != 0 and defval is not None: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
699 return defval |
16379
5cbfbb838198
scmutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents:
16208
diff
changeset
|
700 return repo[val].rev() |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
701 |
20559
165b117ffc1e
scmutil: changed revrange code not to use append
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20551
diff
changeset
|
702 seen, l = set(), revset.baseset([]) |
24175
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
703 |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
704 revsetaliases = [alias for (alias, _) in |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
705 repo.ui.configitems("revsetalias")] |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
706 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
707 for spec in revs: |
16390
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
708 if l and not seen: |
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
709 seen = set(l) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
710 # attempt to parse old-style ranges first to deal with |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
711 # things like old-tag which contain query metacharacters |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
712 try: |
24175
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
713 # ... except for revset aliases without arguments. These |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
714 # should be parsed as soon as possible, because they might |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
715 # clash with a hash prefix. |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
716 if spec in revsetaliases: |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
717 raise error.RepoLookupError |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
718 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
719 if isinstance(spec, int): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
720 seen.add(spec) |
20798
170d6d591a7d
scmutil: fix revrange when multiple revs are specified
Durham Goode <durham@fb.com>
parents:
20781
diff
changeset
|
721 l = l + revset.baseset([spec]) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
722 continue |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
723 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
724 if _revrangesep in spec: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
725 start, end = spec.split(_revrangesep, 1) |
24175
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
726 if start in revsetaliases or end in revsetaliases: |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
727 raise error.RepoLookupError |
c4e3e7b031b7
revrange: don't parse revset aliases as hash prefixes (issue4553)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24114
diff
changeset
|
728 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
729 start = revfix(repo, start, 0) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
730 end = revfix(repo, end, len(repo) - 1) |
20699
58c32a9c8e7b
hg log: solves bug regarding hg log -r 0:null (issue4039)
Cristian Zamfir <cristi_zmf@yahoo.com>
parents:
20090
diff
changeset
|
731 if end == nullrev and start < 0: |
18466
ac0c12123743
log: remove any ancestors of nullrev (issue3772)
Sean Farley <sean.michael.farley@gmail.com>
parents:
18450
diff
changeset
|
732 start = nullrev |
17992
c95210b82c0e
clfilter: remove usage of `range` and `xrange` in scmutil.revrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17937
diff
changeset
|
733 rangeiter = repo.changelog.revs(start, end) |
16390
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
734 if not seen and not l: |
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
735 # by far the most common case: revs = ["-1:0"] |
20559
165b117ffc1e
scmutil: changed revrange code not to use append
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20551
diff
changeset
|
736 l = revset.baseset(rangeiter) |
16390
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
737 # defer syncing seen until next iteration |
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
738 continue |
17992
c95210b82c0e
clfilter: remove usage of `range` and `xrange` in scmutil.revrange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17937
diff
changeset
|
739 newrevs = set(rangeiter) |
16390
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
740 if seen: |
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
741 newrevs.difference_update(seen) |
16814
9da5a2864f3f
scmutil: seen.union should be seen.update (issue3476)
Bryan O'Sullivan <bryano@fb.com>
parents:
16790
diff
changeset
|
742 seen.update(newrevs) |
16390
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
743 else: |
4df76d5506a9
scmutil: speed up revrange
Bryan O'Sullivan <bryano@fb.com>
parents:
16383
diff
changeset
|
744 seen = newrevs |
20798
170d6d591a7d
scmutil: fix revrange when multiple revs are specified
Durham Goode <durham@fb.com>
parents:
20781
diff
changeset
|
745 l = l + revset.baseset(sorted(newrevs, reverse=start > end)) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
746 continue |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
747 elif spec and spec in repo: # single unquoted rev |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
748 rev = revfix(repo, spec, None) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
749 if rev in seen: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
750 continue |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
751 seen.add(rev) |
20798
170d6d591a7d
scmutil: fix revrange when multiple revs are specified
Durham Goode <durham@fb.com>
parents:
20781
diff
changeset
|
752 l = l + revset.baseset([rev]) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
753 continue |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
754 except error.RepoLookupError: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
755 pass |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
756 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
757 # fall through to new-style queries if old-style fails |
20781
8ecfa225bd16
revrange: pass repo to revset parser
Matt Mackall <mpm@selenic.com>
parents:
20715
diff
changeset
|
758 m = revset.match(repo.ui, spec, repo) |
20551
efae655fd363
scmutil: changed revrange to return lazysets for new style revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
759 if seen or l: |
24114
fafd9a1284cf
revset: make match function initiate query from full set by default
Yuya Nishihara <yuya@tcha.org>
parents:
23686
diff
changeset
|
760 dl = [r for r in m(repo) if r not in seen] |
20798
170d6d591a7d
scmutil: fix revrange when multiple revs are specified
Durham Goode <durham@fb.com>
parents:
20781
diff
changeset
|
761 l = l + revset.baseset(dl) |
20551
efae655fd363
scmutil: changed revrange to return lazysets for new style revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
762 seen.update(dl) |
efae655fd363
scmutil: changed revrange to return lazysets for new style revsets
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20526
diff
changeset
|
763 else: |
24114
fafd9a1284cf
revset: make match function initiate query from full set by default
Yuya Nishihara <yuya@tcha.org>
parents:
23686
diff
changeset
|
764 l = m(repo) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
765 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
766 return l |
14320 | 767 |
768 def expandpats(pats): | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
769 '''Expand bare globs when running on windows. |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
770 On posix we assume it already has already been done by sh.''' |
14320 | 771 if not util.expandglobs: |
772 return list(pats) | |
773 ret = [] | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
774 for kindpat in pats: |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
775 kind, pat = matchmod._patsplit(kindpat, None) |
14320 | 776 if kind is None: |
777 try: | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
778 globbed = glob.glob(pat) |
14320 | 779 except re.error: |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
780 globbed = [pat] |
14320 | 781 if globbed: |
782 ret.extend(globbed) | |
783 continue | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
784 ret.append(kindpat) |
14320 | 785 return ret |
786 | |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
787 def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath'): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
788 '''Return a matcher and the patterns that were used. |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
789 The matcher will warn about bad matches.''' |
14320 | 790 if pats == ("",): |
791 pats = [] | |
792 if not globbed and default == 'relpath': | |
793 pats = expandpats(pats or []) | |
14670
19197fa4c41c
scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents:
14669
diff
changeset
|
794 |
19197fa4c41c
scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents:
14669
diff
changeset
|
795 m = ctx.match(pats, opts.get('include'), opts.get('exclude'), |
14669
2d2604adfdd6
context: add a match builder method
Matt Mackall <mpm@selenic.com>
parents:
14527
diff
changeset
|
796 default) |
14320 | 797 def badfn(f, msg): |
24338
ca1365078c86
scmutil: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24175
diff
changeset
|
798 ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg)) |
14320 | 799 m.bad = badfn |
24447
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
800 if m.always(): |
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
801 pats = [] |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
802 return m, pats |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
803 |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
804 def match(ctx, pats=[], opts={}, globbed=False, default='relpath'): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
805 '''Return a matcher that will warn about bad matches.''' |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
806 return matchandpats(ctx, pats, opts, globbed, default)[0] |
14320 | 807 |
808 def matchall(repo): | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
809 '''Return a matcher that will efficiently match everything.''' |
14320 | 810 return matchmod.always(repo.root, repo.getcwd()) |
811 | |
812 def matchfiles(repo, files): | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
813 '''Return a matcher that will efficiently match exactly these files.''' |
14320 | 814 return matchmod.exact(repo.root, repo.getcwd(), files) |
815 | |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
816 def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None): |
23533
891aaa7c0c70
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents:
23481
diff
changeset
|
817 m = matcher |
14320 | 818 if dry_run is None: |
819 dry_run = opts.get('dry_run') | |
820 if similarity is None: | |
821 similarity = float(opts.get('similarity') or 0) | |
23533
891aaa7c0c70
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents:
23481
diff
changeset
|
822 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
823 ret = 0 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
824 join = lambda f: os.path.join(prefix, f) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
825 |
23539
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
826 def matchessubrepo(matcher, subpath): |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
827 if matcher.exact(subpath): |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
828 return True |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
829 for f in matcher.files(): |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
830 if f.startswith(subpath): |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
831 return True |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
832 return False |
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
833 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
834 wctx = repo[None] |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
835 for subpath in sorted(wctx.substate): |
23539
cb42050f2dad
addremove: support addremove with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
23537
diff
changeset
|
836 if opts.get('subrepos') or matchessubrepo(m, subpath): |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
837 sub = wctx.sub(subpath) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
838 try: |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
839 submatch = matchmod.narrowmatcher(subpath, m) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
840 if sub.addremove(submatch, prefix, opts, dry_run, similarity): |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
841 ret = 1 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
842 except error.LookupError: |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
843 repo.ui.status(_("skipping missing subrepository: %s\n") |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
844 % join(subpath)) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
845 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
846 rejected = [] |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
847 origbad = m.bad |
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
848 def badfn(f, msg): |
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
849 if f in m.files(): |
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
850 origbad(f, msg) |
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
851 rejected.append(f) |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
852 |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
853 m.bad = badfn |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
854 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
855 m.bad = origbad |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
856 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
857 unknownset = set(unknown + forgotten) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
858 toprint = unknownset.copy() |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
859 toprint.update(deleted) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
860 for abs in sorted(toprint): |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
861 if repo.ui.verbose or not m.exact(abs): |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
862 if abs in unknownset: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
863 status = _('adding %s\n') % m.uipath(abs) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
864 else: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
865 status = _('removing %s\n') % m.uipath(abs) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
866 repo.ui.status(status) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
867 |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
868 renames = _findrenames(repo, m, added + unknown, removed + deleted, |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
869 similarity) |
14320 | 870 |
871 if not dry_run: | |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
872 _markchanges(repo, unknown + forgotten, deleted, renames) |
14320 | 873 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
874 for f in rejected: |
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
875 if f in m.files(): |
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
876 return 1 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
877 return ret |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
878 |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
879 def marktouched(repo, files, similarity=0.0): |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
880 '''Assert that files have somehow been operated upon. files are relative to |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
881 the repo root.''' |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
882 m = matchfiles(repo, files) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
883 rejected = [] |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
884 m.bad = lambda x, y: rejected.append(x) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
885 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
886 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
887 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
888 if repo.ui.verbose: |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
889 unknownset = set(unknown + forgotten) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
890 toprint = unknownset.copy() |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
891 toprint.update(deleted) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
892 for abs in sorted(toprint): |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
893 if abs in unknownset: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
894 status = _('adding %s\n') % abs |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
895 else: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
896 status = _('removing %s\n') % abs |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
897 repo.ui.status(status) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
898 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
899 renames = _findrenames(repo, m, added + unknown, removed + deleted, |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
900 similarity) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
901 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
902 _markchanges(repo, unknown + forgotten, deleted, renames) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
903 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
904 for f in rejected: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
905 if f in m.files(): |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
906 return 1 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
907 return 0 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
908 |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
909 def _interestingfiles(repo, matcher): |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
910 '''Walk dirstate with matcher, looking for files that addremove would care |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
911 about. |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
912 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
913 This is different from dirstate.status because it doesn't care about |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
914 whether files are modified or clean.''' |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
915 added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
20006
diff
changeset
|
916 audit_path = pathutil.pathauditor(repo.root) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
917 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
918 ctx = repo[None] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
919 dirstate = repo.dirstate |
19655
1d07bf106c2a
addremove: don't do full walks
Siddharth Agarwal <sid0@fb.com>
parents:
19509
diff
changeset
|
920 walkresults = dirstate.walk(matcher, sorted(ctx.substate), True, False, |
1d07bf106c2a
addremove: don't do full walks
Siddharth Agarwal <sid0@fb.com>
parents:
19509
diff
changeset
|
921 full=False) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
922 for abs, st in walkresults.iteritems(): |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
923 dstate = dirstate[abs] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
924 if dstate == '?' and audit_path.check(abs): |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
925 unknown.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
926 elif dstate != 'r' and not st: |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
927 deleted.append(abs) |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
928 elif dstate == 'r' and st: |
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
929 forgotten.append(abs) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
930 # for finding renames |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
931 elif dstate == 'r' and not st: |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
932 removed.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
933 elif dstate == 'a': |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
934 added.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
935 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
936 return added, unknown, deleted, removed, forgotten |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
937 |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
938 def _findrenames(repo, matcher, added, removed, similarity): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
939 '''Find renames from removed files to added ones.''' |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
940 renames = {} |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
941 if similarity > 0: |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
942 for old, new, score in similar.findrenames(repo, added, removed, |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
943 similarity): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
944 if (repo.ui.verbose or not matcher.exact(old) |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
945 or not matcher.exact(new)): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
946 repo.ui.status(_('recording removal of %s as rename to %s ' |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
947 '(%d%% similar)\n') % |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
948 (matcher.rel(old), matcher.rel(new), |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
949 score * 100)) |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
950 renames[new] = old |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
951 return renames |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
952 |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
953 def _markchanges(repo, unknown, deleted, renames): |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
954 '''Marks the files in unknown as added, the files in deleted as removed, |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
955 and the files in renames as copied.''' |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
956 wctx = repo[None] |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
957 wlock = repo.wlock() |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
958 try: |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
959 wctx.forget(deleted) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
960 wctx.add(unknown) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
961 for new, old in renames.iteritems(): |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
962 wctx.copy(old, new) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
963 finally: |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
964 wlock.release() |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
965 |
14320 | 966 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
967 """Update the dirstate to reflect the intent of copying src to dst. For | |
968 different reasons it might not end with dst being marked as copied from src. | |
969 """ | |
970 origsrc = repo.dirstate.copied(src) or src | |
971 if dst == origsrc: # copying back a copy? | |
972 if repo.dirstate[dst] not in 'mn' and not dryrun: | |
973 repo.dirstate.normallookup(dst) | |
974 else: | |
975 if repo.dirstate[origsrc] == 'a' and origsrc == src: | |
976 if not ui.quiet: | |
977 ui.warn(_("%s has not been committed yet, so no copy " | |
978 "data will be stored for %s.\n") | |
979 % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd))) | |
980 if repo.dirstate[dst] in '?r' and not dryrun: | |
981 wctx.add([dst]) | |
982 elif not dryrun: | |
983 wctx.copy(origsrc, dst) | |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
984 |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
985 def readrequires(opener, supported): |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
986 '''Reads and parses .hg/requires and checks if all entries found |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
987 are in the list of supported features.''' |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
988 requirements = set(opener.read("requires").splitlines()) |
14746
72e4fcb43227
requirements: show all missing features in the error message.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
14720
diff
changeset
|
989 missings = [] |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
990 for r in requirements: |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
991 if r not in supported: |
14484
4582a4dd1817
requires: note apparent corruption
Matt Mackall <mpm@selenic.com>
parents:
14483
diff
changeset
|
992 if not r or not r[0].isalnum(): |
4582a4dd1817
requires: note apparent corruption
Matt Mackall <mpm@selenic.com>
parents:
14483
diff
changeset
|
993 raise error.RequirementError(_(".hg/requires file is corrupt")) |
14746
72e4fcb43227
requirements: show all missing features in the error message.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
14720
diff
changeset
|
994 missings.append(r) |
72e4fcb43227
requirements: show all missing features in the error message.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
14720
diff
changeset
|
995 missings.sort() |
72e4fcb43227
requirements: show all missing features in the error message.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
14720
diff
changeset
|
996 if missings: |
16683 | 997 raise error.RequirementError( |
20820
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
998 _("repository requires features unknown to this Mercurial: %s") |
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
999 % " ".join(missings), |
20715
b93791e0de25
require: provide a link to a wiki page in addition of suggesting upgrade
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20702
diff
changeset
|
1000 hint=_("see http://mercurial.selenic.com/wiki/MissingRequirement" |
20820
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
1001 " for more information")) |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1002 return requirements |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1003 |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1004 class filecachesubentry(object): |
20042
9a72d3886888
scmutil.filecacheentry: make stat argument to constructor mandatory
Siddharth Agarwal <sid0@fb.com>
parents:
20033
diff
changeset
|
1005 def __init__(self, path, stat): |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1006 self.path = path |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1007 self.cachestat = None |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1008 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1009 |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1010 if stat: |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1011 self.cachestat = filecachesubentry.stat(self.path) |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1012 |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1013 if self.cachestat: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1014 self._cacheable = self.cachestat.cacheable() |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1015 else: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1016 # None means we don't know yet |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1017 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1018 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1019 def refresh(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1020 if self.cacheable(): |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1021 self.cachestat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1022 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1023 def cacheable(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1024 if self._cacheable is not None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1025 return self._cacheable |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1026 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1027 # we don't know yet, assume it is for now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1028 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1029 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1030 def changed(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1031 # no point in going further if we can't cache it |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1032 if not self.cacheable(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1033 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1034 |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1035 newstat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1036 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1037 # we may not know if it's cacheable yet, check again now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1038 if newstat and self._cacheable is None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1039 self._cacheable = newstat.cacheable() |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1040 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1041 # check again |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1042 if not self._cacheable: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1043 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1044 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1045 if self.cachestat != newstat: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1046 self.cachestat = newstat |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1047 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1048 else: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1049 return False |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1050 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1051 @staticmethod |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1052 def stat(path): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1053 try: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1054 return util.cachestat(path) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1055 except OSError, e: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1056 if e.errno != errno.ENOENT: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1057 raise |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1058 |
20044
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1059 class filecacheentry(object): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1060 def __init__(self, paths, stat=True): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1061 self._entries = [] |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1062 for path in paths: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1063 self._entries.append(filecachesubentry(path, stat)) |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1064 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1065 def changed(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1066 '''true if any entry has changed''' |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1067 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1068 if entry.changed(): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1069 return True |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1070 return False |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1071 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1072 def refresh(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1073 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1074 entry.refresh() |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1075 |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1076 class filecache(object): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1077 '''A property like decorator that tracks files under .hg/ for updates. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1078 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1079 Records stat info when called in _filecache. |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1080 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1081 On subsequent calls, compares old stat info with new info, and recreates the |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1082 object when any of the files changes, updating the new stat info in |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1083 _filecache. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1084 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1085 Mercurial either atomic renames or appends for files under .hg, |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1086 so to ensure the cache is reliable we need the filesystem to be able |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1087 to tell us if a file has been replaced. If it can't, we fallback to |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1088 recreating the object on every call (essentially the same behaviour as |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1089 propertycache). |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1090 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1091 ''' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1092 def __init__(self, *paths): |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1093 self.paths = paths |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1094 |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1095 def join(self, obj, fname): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1096 """Used to compute the runtime path of a cached file. |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1097 |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1098 Users should subclass filecache and provide their own version of this |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1099 function to call the appropriate join function on 'obj' (an instance |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1100 of the class that its member function was decorated). |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1101 """ |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1102 return obj.join(fname) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1103 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1104 def __call__(self, func): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1105 self.func = func |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1106 self.name = func.__name__ |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1107 return self |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1108 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1109 def __get__(self, obj, type=None): |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1110 # do we need to check if the file changed? |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1111 if self.name in obj.__dict__: |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1112 assert self.name in obj._filecache, self.name |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1113 return obj.__dict__[self.name] |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1114 |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1115 entry = obj._filecache.get(self.name) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1116 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1117 if entry: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1118 if entry.changed(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1119 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1120 else: |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1121 paths = [self.join(obj, path) for path in self.paths] |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1122 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1123 # We stat -before- creating the object so our cache doesn't lie if |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1124 # a writer modified between the time we read and stat |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1125 entry = filecacheentry(paths, True) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1126 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1127 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1128 obj._filecache[self.name] = entry |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1129 |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1130 obj.__dict__[self.name] = entry.obj |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1131 return entry.obj |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1132 |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1133 def __set__(self, obj, value): |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1134 if self.name not in obj._filecache: |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1135 # we add an entry for the missing value because X in __dict__ |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1136 # implies X in _filecache |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1137 paths = [self.join(obj, path) for path in self.paths] |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1138 ce = filecacheentry(paths, False) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1139 obj._filecache[self.name] = ce |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1140 else: |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1141 ce = obj._filecache[self.name] |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1142 |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1143 ce.obj = value # update cached copy |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1144 obj.__dict__[self.name] = value # update copy returned by obj.x |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1145 |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1146 def __delete__(self, obj): |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1147 try: |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1148 del obj.__dict__[self.name] |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1149 except KeyError: |
18177
203b7a759218
scmutil: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents:
17992
diff
changeset
|
1150 raise AttributeError(self.name) |