Mercurial > hg
annotate mercurial/scmutil.py @ 37953:4237d07fad2c
hgweb: use template context to render {files} of changelist entries
This is a preferred way to process nested templates.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 03 Apr 2018 23:33:54 +0900 |
parents | 32bc3815efae |
children | 2f86f259aefa |
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 |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
8 from __future__ import absolute_import |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
9 |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
10 import errno |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
11 import glob |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29336
diff
changeset
|
12 import hashlib |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
13 import os |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
14 import re |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
15 import socket |
34461
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
16 import subprocess |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
17 import weakref |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
18 |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
19 from .i18n import _ |
32658
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
20 from .node import ( |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
21 bin, |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
22 hex, |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
23 nullid, |
34327
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
24 short, |
32658
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
25 wdirid, |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
26 wdirrev, |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
27 ) |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
28 |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
29 from . import ( |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
30 encoding, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
31 error, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
32 match as matchmod, |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
33 obsolete, |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
34 obsutil, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
35 pathutil, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
36 phases, |
30305
af7c60988f6e
py3: make scmutil.rcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30109
diff
changeset
|
37 pycompat, |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
38 revsetlang, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
39 similar, |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
40 url, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
41 util, |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
42 vfs, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
43 ) |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
44 |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
45 from .utils import ( |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37094
diff
changeset
|
46 procutil, |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
47 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
48 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
49 |
34645 | 50 if pycompat.iswindows: |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
51 from . import scmwindows as scmplatform |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
52 else: |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
53 from . import scmposix as scmplatform |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
54 |
30314
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30309
diff
changeset
|
55 termsize = scmplatform.termsize |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
56 |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
57 class status(tuple): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
58 '''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
|
59 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
|
60 ''' |
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 __slots__ = () |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
63 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
64 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
|
65 clean): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
66 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
|
67 ignored, clean)) |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
68 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
69 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
70 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
|
71 '''files that have been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
72 return self[0] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
73 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
74 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
75 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
|
76 '''files that have been added''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
77 return self[1] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
78 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
79 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
80 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
|
81 '''files that have been removed''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
82 return self[2] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
83 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
84 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
85 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
|
86 '''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
|
87 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
|
88 ''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
89 return self[3] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
90 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
91 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
92 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
|
93 '''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
|
94 return self[4] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
95 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
96 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
97 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
|
98 '''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
|
99 return self[5] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
100 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
101 @property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
102 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
|
103 '''files that have not been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
104 return self[6] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
105 |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
106 def __repr__(self, *args, **kwargs): |
37921
a8a7ccec1783
scmutil: fix __repr__ of status tuple
Augie Fackler <augie@google.com>
parents:
37869
diff
changeset
|
107 return ((r'<status modified=%s, added=%s, removed=%s, deleted=%s, ' |
a8a7ccec1783
scmutil: fix __repr__ of status tuple
Augie Fackler <augie@google.com>
parents:
37869
diff
changeset
|
108 r'unknown=%s, ignored=%s, clean=%s>') % |
37942
32bc3815efae
stringutil: flip the default of pprint() to bprefix=False
Yuya Nishihara <yuya@tcha.org>
parents:
37921
diff
changeset
|
109 tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self)) |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
110 |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
111 def itersubrepos(ctx1, ctx2): |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
112 """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
|
113 # 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
|
114 # 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
|
115 # 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
|
116 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
|
117 subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
25418
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
118 |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
119 missing = set() |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
120 |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
121 for subpath in ctx2.substate: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
122 if subpath not in ctx1.substate: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
123 del subpaths[subpath] |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
124 missing.add(subpath) |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
125 |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
126 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
|
127 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
|
128 |
25418
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
129 # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
130 # status and diff will have an accurate result when it does |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
131 # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
132 # against itself. |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
133 for subpath in missing: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
134 yield subpath, ctx2.nullsub(subpath, ctx1) |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
135 |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
136 def nochangesfound(ui, repo, excluded=None): |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
137 '''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
|
138 nodes excluded from the push/pull. |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
139 ''' |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
140 secretlist = [] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
141 if excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
142 for n in excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
143 ctx = repo[n] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
144 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
|
145 secretlist.append(n) |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
146 |
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
147 if secretlist: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
148 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
|
149 % len(secretlist)) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
150 else: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
151 ui.status(_("no changes found\n")) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
152 |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
153 def callcatch(ui, func): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
154 """call func() with global exception handling |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
155 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
156 return func() if no exception happens. otherwise do some error handling |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
157 and return an exit code accordingly. does not handle all exceptions. |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
158 """ |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
159 try: |
32041
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
160 try: |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
161 return func() |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
162 except: # re-raises |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
163 ui.traceback() |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
164 raise |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
165 # Global exception handling, alphabetically |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
166 # Mercurial-specific first, followed by built-in and library exceptions |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
167 except error.LockHeld as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
168 if inst.errno == errno.ETIMEDOUT: |
32088
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
169 reason = _('timed out waiting for lock held by %r') % inst.locker |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
170 else: |
32088
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
171 reason = _('lock held by %r') % inst.locker |
36641
77f98867538f
py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents:
36569
diff
changeset
|
172 ui.warn(_("abort: %s: %s\n") |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
173 % (inst.desc or stringutil.forcebytestr(inst.filename), reason)) |
32088
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
174 if not inst.locker: |
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
175 ui.warn(_("(lock might be very busy)\n")) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
176 except error.LockUnavailable as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
177 ui.warn(_("abort: could not lock %s: %s\n") % |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
178 (inst.desc or stringutil.forcebytestr(inst.filename), |
36641
77f98867538f
py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents:
36569
diff
changeset
|
179 encoding.strtolocal(inst.strerror))) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
180 except error.OutOfBandError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
181 if inst.args: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
182 msg = _("abort: remote error:\n") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
183 else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
184 msg = _("abort: remote error\n") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
185 ui.warn(msg) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
186 if inst.args: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
187 ui.warn(''.join(inst.args)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
188 if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
189 ui.warn('(%s)\n' % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
190 except error.RepoError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
191 ui.warn(_("abort: %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
192 if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
193 ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
194 except error.ResponseError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
195 ui.warn(_("abort: %s") % inst.args[0]) |
36661
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36658
diff
changeset
|
196 msg = inst.args[1] |
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36658
diff
changeset
|
197 if isinstance(msg, type(u'')): |
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36658
diff
changeset
|
198 msg = pycompat.sysbytes(msg) |
36695
c442c4a92ae8
scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents:
36661
diff
changeset
|
199 if not isinstance(msg, bytes): |
c442c4a92ae8
scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents:
36661
diff
changeset
|
200 ui.warn(" %r\n" % (msg,)) |
c442c4a92ae8
scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents:
36661
diff
changeset
|
201 elif not msg: |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
202 ui.warn(_(" empty string\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
203 else: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
204 ui.warn("\n%r\n" % stringutil.ellipsis(msg)) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
205 except error.CensoredNodeError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
206 ui.warn(_("abort: file censored %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
207 except error.RevlogError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
208 ui.warn(_("abort: %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
209 except error.InterventionRequired as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
210 ui.warn("%s\n" % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
211 if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
212 ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
213 return 1 |
32659
7b17f9de6d3e
revlog: map rev(wdirid) to WdirUnsupported exception
Yuya Nishihara <yuya@tcha.org>
parents:
32658
diff
changeset
|
214 except error.WdirUnsupported: |
7b17f9de6d3e
revlog: map rev(wdirid) to WdirUnsupported exception
Yuya Nishihara <yuya@tcha.org>
parents:
32658
diff
changeset
|
215 ui.warn(_("abort: working directory revision cannot be specified\n")) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
216 except error.Abort as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
217 ui.warn(_("abort: %s\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
218 if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
219 ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
220 except ImportError as inst: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
221 ui.warn(_("abort: %s!\n") % stringutil.forcebytestr(inst)) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
222 m = stringutil.forcebytestr(inst).split()[-1] |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
223 if m in "mpatch bdiff".split(): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
224 ui.warn(_("(did you forget to compile extensions?)\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
225 elif m in "zlib".split(): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
226 ui.warn(_("(is your Python install correct?)\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
227 except IOError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
228 if util.safehasattr(inst, "code"): |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
229 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst)) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
230 elif util.safehasattr(inst, "reason"): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
231 try: # usually it is in the form (errno, strerror) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
232 reason = inst.reason.args[1] |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
233 except (AttributeError, IndexError): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
234 # it might be anything, for example a string |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
235 reason = inst.reason |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
236 if isinstance(reason, unicode): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
237 # SSLError of Python 2.7.9 contains a unicode |
32152
994b0b1c77d6
py3: use encoding.unitolocal instead of .encode(encoding.encoding)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32115
diff
changeset
|
238 reason = encoding.unitolocal(reason) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
239 ui.warn(_("abort: error: %s\n") % reason) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
240 elif (util.safehasattr(inst, "args") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
241 and inst.args and inst.args[0] == errno.EPIPE): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
242 pass |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
243 elif getattr(inst, "strerror", None): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
244 if getattr(inst, "filename", None): |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
34005
diff
changeset
|
245 ui.warn(_("abort: %s: %s\n") % ( |
36641
77f98867538f
py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents:
36569
diff
changeset
|
246 encoding.strtolocal(inst.strerror), |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
247 stringutil.forcebytestr(inst.filename))) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
248 else: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
34005
diff
changeset
|
249 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
250 else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
251 raise |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
252 except OSError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
253 if getattr(inst, "filename", None) is not None: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
34005
diff
changeset
|
254 ui.warn(_("abort: %s: '%s'\n") % ( |
36641
77f98867538f
py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents:
36569
diff
changeset
|
255 encoding.strtolocal(inst.strerror), |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
256 stringutil.forcebytestr(inst.filename))) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
257 else: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
34005
diff
changeset
|
258 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
259 except MemoryError: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
260 ui.warn(_("abort: out of memory\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
261 except SystemExit as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
262 # Commands shouldn't sys.exit directly, but give a return code. |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
263 # Just in case catch this and and pass exit code to caller. |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
264 return inst.code |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
265 except socket.error as inst: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
266 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1])) |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
267 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
268 return -1 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
269 |
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
270 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
|
271 # 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
|
272 # 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
|
273 if lbl in ['tip', '.', 'null']: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
274 raise error.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
|
275 for c in (':', '\0', '\n', '\r'): |
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
276 if c in lbl: |
36569
bb5f5c1c3c1b
scmutil: fix a repr in an error message on Python 3
Augie Fackler <augie@google.com>
parents:
36422
diff
changeset
|
277 raise error.Abort( |
bb5f5c1c3c1b
scmutil: fix a repr in an error message on Python 3
Augie Fackler <augie@google.com>
parents:
36422
diff
changeset
|
278 _("%r cannot be used in a name") % pycompat.bytestr(c)) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
279 try: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
280 int(lbl) |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
281 raise error.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
|
282 except ValueError: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
283 pass |
36145
4f3e989536c3
label: enforce the lack of leading or trailing white space
Boris Feld <boris.feld@octobus.net>
parents:
36137
diff
changeset
|
284 if lbl.strip() != lbl: |
4f3e989536c3
label: enforce the lack of leading or trailing white space
Boris Feld <boris.feld@octobus.net>
parents:
36137
diff
changeset
|
285 raise error.Abort(_("leading or trailing whitespace in name %r") % lbl) |
17817
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
286 |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
287 def checkfilename(f): |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
288 '''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
|
289 if '\r' in f or '\n' in f: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
290 raise error.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f) |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
291 |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
292 def checkportable(ui, f): |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
293 '''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
|
294 checkfilename(f) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
295 abort, warn = checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
296 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
|
297 msg = util.checkwinfilename(f) |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
298 if msg: |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37094
diff
changeset
|
299 msg = "%s: %s" % (msg, procutil.shellquote(f)) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
300 if abort: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
301 raise error.Abort(msg) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
302 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
|
303 |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
304 def checkportabilityalert(ui): |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
305 '''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
|
306 non-portable filenames''' |
33499
0407a51b9d8c
codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents:
33352
diff
changeset
|
307 val = ui.config('ui', 'portablefilenames') |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
308 lval = val.lower() |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36836
diff
changeset
|
309 bval = stringutil.parsebool(val) |
34645 | 310 abort = pycompat.iswindows or lval == 'abort' |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
311 warn = bval or lval == 'warn' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
312 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
|
313 raise error.ConfigError( |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
314 _("ui.portablefilenames value is invalid ('%s')") % val) |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
315 return abort, warn |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
316 |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
317 class casecollisionauditor(object): |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
318 def __init__(self, ui, abort, dirstate): |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
319 self._ui = ui |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
320 self._abort = abort |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
321 allfiles = '\0'.join(dirstate._map) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
322 self._loweredfiles = set(encoding.lower(allfiles).split('\0')) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
323 self._dirstate = dirstate |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
324 # 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
|
325 # 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
|
326 # same filename twice. |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
327 self._newfiles = set() |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
328 |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 msg = _('possible case-folding collision for %s') % f |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
335 if self._abort: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
336 raise error.Abort(msg) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
337 self._ui.warn(_("warning: %s\n") % msg) |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
338 self._loweredfiles.add(fl) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
339 self._newfiles.add(f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
340 |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
341 def filteredhash(repo, maxrev): |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
342 """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
|
343 |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 tipnode changing. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
349 |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
350 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
|
351 that SHA-1 digest. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
352 """ |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
353 cl = repo.changelog |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
354 if not cl.filteredrevs: |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
355 return None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
356 key = None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
357 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
|
358 if revs: |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29336
diff
changeset
|
359 s = hashlib.sha1() |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
360 for rev in revs: |
31349
719e64bf9ec2
scmutil: fix key generation to portably bytestringify integer
Augie Fackler <augie@google.com>
parents:
31285
diff
changeset
|
361 s.update('%d;' % rev) |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
362 key = s.digest() |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
363 return key |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
364 |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
365 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
|
366 '''yield every hg repository under path, always recursively. |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
17037
diff
changeset
|
367 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
|
368 def errhandler(err): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
369 if err.filename == path: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
370 raise err |
14961
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
371 samestat = getattr(os.path, 'samestat', None) |
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
372 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
|
373 def adddir(dirlst, dirname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
374 dirstat = os.stat(dirname) |
36338
ddd9474d2e08
walkrepos: don't reimplement any()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36313
diff
changeset
|
375 match = any(samestat(dirstat, lstdirstat) for lstdirstat in dirlst) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
376 if not match: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
377 dirlst.append(dirstat) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
378 return not match |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
379 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
380 followsym = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
381 |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
382 if (seen_dirs is None) and followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
383 seen_dirs = [] |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
384 adddir(seen_dirs, path) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
385 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
|
386 dirs.sort() |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
387 if '.hg' in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
388 yield root # found a repository |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
389 qroot = os.path.join(root, '.hg', 'patches') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
390 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
|
391 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
|
392 if recurse: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
393 # avoid recursing inside the .hg directory |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
394 dirs.remove('.hg') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
395 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
396 dirs[:] = [] # don't descend further |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
397 elif followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
398 newdirs = [] |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
399 for d in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
400 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
|
401 if adddir(seen_dirs, fname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
402 if os.path.islink(fname): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
403 for hgname in walkrepos(fname, True, seen_dirs): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
404 yield hgname |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
405 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
406 newdirs.append(d) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
407 dirs[:] = newdirs |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
408 |
32658
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
409 def binnode(ctx): |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
410 """Return binary node id for a given basectx""" |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
411 node = ctx.node() |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
412 if node is None: |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
413 return wdirid |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
414 return node |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32656
diff
changeset
|
415 |
32656
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32270
diff
changeset
|
416 def intrev(ctx): |
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32270
diff
changeset
|
417 """Return integer for a given basectx that can be used in comparison or |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
418 arithmetic operation""" |
32656
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32270
diff
changeset
|
419 rev = ctx.rev() |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
420 if rev is None: |
25739
3dabc9b7494a
changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Yuya Nishihara <yuya@tcha.org>
parents:
25660
diff
changeset
|
421 return wdirrev |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
422 return rev |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
423 |
34327
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
424 def formatchangeid(ctx): |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
425 """Format changectx as '{rev}:{node|formatnode}', which is the default |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35748
diff
changeset
|
426 template provided by logcmdutil.changesettemplater""" |
34327
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
427 repo = ctx.repo() |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
428 return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
429 |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
430 def formatrevnode(ui, rev, node): |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
431 """Format given revision and node depending on the current verbosity""" |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
432 if ui.debugflag: |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
433 hexfunc = hex |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
434 else: |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
435 hexfunc = short |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
436 return '%d:%s' % (rev, hexfunc(node)) |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34146
diff
changeset
|
437 |
37678
5f8f013e7d52
scmutil: rename resolvepartialhexnodeid() to resolvehexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37677
diff
changeset
|
438 def resolvehexnodeidprefix(repo, prefix): |
5f8f013e7d52
scmutil: rename resolvepartialhexnodeid() to resolvehexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37677
diff
changeset
|
439 # Uses unfiltered repo because it's faster when prefix is ambiguous/ |
37708
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
440 # This matches the shortesthexnodeidprefix() function below. |
37504
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
441 node = repo.unfiltered().changelog._partialmatch(prefix) |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
442 if node is None: |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
443 return |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
444 repo.changelog.rev(node) # make sure node isn't filtered |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
445 return node |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
446 |
37709
7b2955624777
scmutil: make shortesthexnodeidprefix() take a full binary nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37708
diff
changeset
|
447 def shortesthexnodeidprefix(repo, node, minlength=1): |
37680
e743b8524d60
scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37679
diff
changeset
|
448 """Find the shortest unambiguous prefix that matches hexnode.""" |
37708
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
449 # _partialmatch() of filtered changelog could take O(len(repo)) time, |
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
450 # which would be unacceptably slow. so we look for hash collision in |
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
451 # unfiltered space, which means some hashes may be slightly longer. |
37865
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
452 try: |
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
453 return repo.unfiltered().changelog.shortest(node, minlength) |
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
454 except error.LookupError: |
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
455 raise error.RepoLookupError() |
37680
e743b8524d60
scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37679
diff
changeset
|
456 |
37350
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
457 def isrevsymbol(repo, symbol): |
37677
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
458 """Checks if a symbol exists in the repo. |
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
459 |
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
460 See revsymbol() for details. Raises error.LookupError if the symbol is an |
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
461 ambiguous nodeid prefix. |
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
462 """ |
37350
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
463 try: |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
464 revsymbol(repo, symbol) |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
465 return True |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
466 except error.RepoLookupError: |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
467 return False |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
468 |
37271
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
469 def revsymbol(repo, symbol): |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
470 """Returns a context given a single revision symbol (as string). |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
471 |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
472 This is similar to revsingle(), but accepts only a single revision symbol, |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
473 i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
474 not "max(public())". |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
475 """ |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
476 if not isinstance(symbol, bytes): |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
477 msg = ("symbol (%s of type %s) was not a string, did you mean " |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
478 "repo[symbol]?" % (symbol, type(symbol))) |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
479 raise error.ProgrammingError(msg) |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
480 try: |
37527
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
481 if symbol in ('.', 'tip', 'null'): |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
482 return repo[symbol] |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
483 |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
484 try: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
485 r = int(symbol) |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
486 if '%d' % r != symbol: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
487 raise ValueError |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
488 l = len(repo.changelog) |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
489 if r < 0: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
490 r += l |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
491 if r < 0 or r >= l and r != wdirrev: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
492 raise ValueError |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
493 return repo[r] |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
494 except error.FilteredIndexError: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
495 raise |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
496 except (ValueError, OverflowError, IndexError): |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
497 pass |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
498 |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
499 if len(symbol) == 40: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
500 try: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
501 node = bin(symbol) |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
502 rev = repo.changelog.rev(node) |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
503 return repo[rev] |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
504 except error.FilteredLookupError: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
505 raise |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
506 except (TypeError, LookupError): |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
507 pass |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
508 |
37529
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
509 # look up bookmarks through the name interface |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
510 try: |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
511 node = repo.names.singlenode(repo, symbol) |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
512 rev = repo.changelog.rev(node) |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
513 return repo[rev] |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
514 except KeyError: |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
515 pass |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
516 |
37679
ab828755e1ea
scmutil: use resolvehexnodeidprefix() from revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37678
diff
changeset
|
517 node = resolvehexnodeidprefix(repo, symbol) |
37530
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
518 if node is not None: |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
519 rev = repo.changelog.rev(node) |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
520 return repo[rev] |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
521 |
37531
6639ac97ec3b
revsymbol: stop delegating to repo.__getitem__ for unhandled symbols (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37530
diff
changeset
|
522 raise error.RepoLookupError(_("unknown revision '%s'") % symbol) |
37527
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
523 |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
524 except error.WdirUnsupported: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
525 return repo[None] |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
526 except (error.FilteredIndexError, error.FilteredLookupError, |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
527 error.FilteredRepoLookupError): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
528 raise _filterederror(repo, symbol) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
529 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
530 def _filterederror(repo, changeid): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
531 """build an exception to be raised about a filtered changeid |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
532 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
533 This is extracted in a function to help extensions (eg: evolve) to |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
534 experiment with various message variants.""" |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
535 if repo.filtername.startswith('visible'): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
536 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
537 # Check if the changeset is obsolete |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
538 unfilteredrepo = repo.unfiltered() |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
539 ctx = revsymbol(unfilteredrepo, changeid) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
540 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
541 # If the changeset is obsolete, enrich the message with the reason |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
542 # that made this changeset not visible |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
543 if ctx.obsolete(): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
544 msg = obsutil._getfilteredreason(repo, changeid, ctx) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
545 else: |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
546 msg = _("hidden revision '%s'") % changeid |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
547 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
548 hint = _('use --hidden to access hidden revisions') |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
549 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
550 return error.FilteredRepoLookupError(msg, hint=hint) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
551 msg = _("filtered revision '%s' (not in '%s' subset)") |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
552 msg %= (changeid, repo.filtername) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
553 return error.FilteredRepoLookupError(msg) |
37271
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37269
diff
changeset
|
554 |
34005
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33798
diff
changeset
|
555 def revsingle(repo, revspec, default='.', localalias=None): |
19509
8963a706e075
revsingle: fix silly API issue (issue2992)
Matt Mackall <mpm@selenic.com>
parents:
19154
diff
changeset
|
556 if not revspec and revspec != 0: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
557 return repo[default] |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
558 |
34005
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33798
diff
changeset
|
559 l = revrange(repo, [revspec], localalias=localalias) |
22814
8110405cf8ae
revset-limit: use boolean testing instead of `len(revs) < 1`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21799
diff
changeset
|
560 if not l: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
561 raise error.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
|
562 return repo[l.last()] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
563 |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
564 def _pairspec(revspec): |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
565 tree = revsetlang.parse(revspec) |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
566 return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall') |
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
567 |
37251
7c0f40f4f7bf
scmutil: introduce deprecated alias for revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37120
diff
changeset
|
568 def revpairnodes(repo, revs): |
37259
d29f6fbd1181
scmutil: deprecate revpairnodes()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37252
diff
changeset
|
569 repo.ui.deprecwarn("revpairnodes is deprecated, please use revpair", "4.6") |
37252
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
570 ctx1, ctx2 = revpair(repo, revs) |
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
571 return ctx1.node(), ctx2.node() |
37251
7c0f40f4f7bf
scmutil: introduce deprecated alias for revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37120
diff
changeset
|
572 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
573 def revpair(repo, revs): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
574 if not revs: |
37252
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
575 return repo['.'], repo[None] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
576 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
577 l = revrange(repo, revs) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
578 |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
579 if not l: |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
580 first = second = None |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
581 elif l.isascending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
582 first = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
583 second = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
584 elif l.isdescending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
585 first = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
586 second = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
587 else: |
22816
20d998395ee7
revpair: use `first` and `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22815
diff
changeset
|
588 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
|
589 second = l.last() |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
590 |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
591 if first is None: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
592 raise error.Abort(_('empty revision range')) |
26836
88c4e97b9669
scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents:
26587
diff
changeset
|
593 if (first == second and len(revs) >= 2 |
88c4e97b9669
scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents:
26587
diff
changeset
|
594 and not all(revrange(repo, [r]) for r in revs)): |
88c4e97b9669
scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents:
26587
diff
changeset
|
595 raise error.Abort(_('empty revision on one side of range')) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
596 |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
597 # if top-level is range expression, the result must always be a pair |
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
598 if first == second and len(revs) == 1 and not _pairspec(revs[0]): |
37252
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
599 return repo[first], repo[None] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
600 |
37252
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
601 return repo[first], repo[second] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
602 |
34005
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33798
diff
changeset
|
603 def revrange(repo, specs, localalias=None): |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
604 """Execute 1 to many revsets and return the union. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
605 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
606 This is the preferred mechanism for executing revsets using user-specified |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
607 config options, such as revset aliases. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
608 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
609 The revsets specified by ``specs`` will be executed via a chained ``OR`` |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
610 expression. If ``specs`` is empty, an empty result is returned. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
611 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
612 ``specs`` can contain integers, in which case they are assumed to be |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
613 revision numbers. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
614 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
615 It is assumed the revsets are already formatted. If you have arguments |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
616 that need to be expanded in the revset, call ``revsetlang.formatspec()`` |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
617 and pass the result as an element of ``specs``. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
618 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
619 Specifying a single revset is allowed. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
620 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
621 Returns a ``revset.abstractsmartset`` which is a list-like interface over |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
622 integer revisions. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
623 """ |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
624 allspecs = [] |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
625 for spec in specs: |
25904
fbaa2de13cf6
revrange: drop old-style parser in favor of revset (API)
Yuya Nishihara <yuya@tcha.org>
parents:
25772
diff
changeset
|
626 if isinstance(spec, int): |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
627 spec = revsetlang.formatspec('rev(%d)', spec) |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
628 allspecs.append(spec) |
34005
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33798
diff
changeset
|
629 return repo.anyrevs(allspecs, user=True, localalias=localalias) |
14320 | 630 |
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
631 def meaningfulparents(repo, ctx): |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
632 """Return list of meaningful (or all if debug) parentrevs for rev. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
633 |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
634 For merges (two non-nullrev revisions) both parents are meaningful. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
635 Otherwise the first parent revision is considered meaningful if it |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
636 is not the preceding revision. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
637 """ |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
638 parents = ctx.parents() |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
639 if len(parents) > 1: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
640 return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
641 if repo.ui.debugflag: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
642 return [parents[0], repo['null']] |
32656
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32270
diff
changeset
|
643 if parents[0].rev() >= intrev(ctx) - 1: |
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
644 return [] |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
645 return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
646 |
14320 | 647 def expandpats(pats): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
648 '''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
|
649 On posix we assume it already has already been done by sh.''' |
14320 | 650 if not util.expandglobs: |
651 return list(pats) | |
652 ret = [] | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
653 for kindpat in pats: |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
654 kind, pat = matchmod._patsplit(kindpat, None) |
14320 | 655 if kind is None: |
656 try: | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
657 globbed = glob.glob(pat) |
14320 | 658 except re.error: |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
659 globbed = [pat] |
14320 | 660 if globbed: |
661 ret.extend(globbed) | |
662 continue | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
663 ret.append(kindpat) |
14320 | 664 return ret |
665 | |
26326
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
666 def matchandpats(ctx, pats=(), opts=None, globbed=False, default='relpath', |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
667 badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
668 '''Return a matcher and the patterns that were used. |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
669 The matcher will warn about bad matches, unless an alternate badfn callback |
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
670 is provided.''' |
14320 | 671 if pats == ("",): |
672 pats = [] | |
26326
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
673 if opts is None: |
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
674 opts = {} |
14320 | 675 if not globbed and default == 'relpath': |
676 pats = expandpats(pats or []) | |
14670
19197fa4c41c
scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents:
14669
diff
changeset
|
677 |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
678 def bad(f, msg): |
24338
ca1365078c86
scmutil: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24175
diff
changeset
|
679 ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg)) |
25466
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
680 |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
681 if badfn is None: |
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
682 badfn = bad |
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
683 |
25466
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
684 m = ctx.match(pats, opts.get('include'), opts.get('exclude'), |
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
685 default, listsubrepos=opts.get('subrepos'), badfn=badfn) |
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
686 |
24447
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
687 if m.always(): |
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
688 pats = [] |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
689 return m, pats |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
690 |
26328
188c1e9506f5
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26327
diff
changeset
|
691 def match(ctx, pats=(), opts=None, globbed=False, default='relpath', |
188c1e9506f5
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26327
diff
changeset
|
692 badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
693 '''Return a matcher that will warn about bad matches.''' |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
694 return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] |
14320 | 695 |
696 def matchall(repo): | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
697 '''Return a matcher that will efficiently match everything.''' |
14320 | 698 return matchmod.always(repo.root, repo.getcwd()) |
699 | |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
700 def matchfiles(repo, files, badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
701 '''Return a matcher that will efficiently match exactly these files.''' |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
702 return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn) |
14320 | 703 |
34854
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
704 def parsefollowlinespattern(repo, rev, pat, msg): |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
705 """Return a file name from `pat` pattern suitable for usage in followlines |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
706 logic. |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
707 """ |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
708 if not matchmod.patkind(pat): |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
709 return pathutil.canonpath(repo.root, repo.getcwd(), pat) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
710 else: |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
711 ctx = repo[rev] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
712 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
713 files = [f for f in ctx if m(f)] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
714 if len(files) != 1: |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
715 raise error.ParseError(msg) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
716 return files[0] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
717 |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
718 def origpath(ui, repo, filepath): |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
719 '''customize where .orig files are created |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
720 |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
721 Fetch user defined path from config file: [ui] origbackuppath = <path> |
34146
9e4f82bc2b0b
scmutil: don't append .orig to backups in origbackuppath (BC)
Mark Thomas <mbthomas@fb.com>
parents:
34022
diff
changeset
|
722 Fall back to default (filepath with .orig suffix) if not specified |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
723 ''' |
33499
0407a51b9d8c
codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents:
33352
diff
changeset
|
724 origbackuppath = ui.config('ui', 'origbackuppath') |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
725 if not origbackuppath: |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
726 return filepath + ".orig" |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
727 |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
728 # Convert filepath from an absolute path into a path inside the repo. |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
729 filepathfromroot = util.normpath(os.path.relpath(filepath, |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
730 start=repo.root)) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
731 |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
732 origvfs = vfs.vfs(repo.wjoin(origbackuppath)) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
733 origbackupdir = origvfs.dirname(filepathfromroot) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
734 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
735 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
736 |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
737 # Remove any files that conflict with the backup file's path |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
738 for f in reversed(list(util.finddirs(filepathfromroot))): |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
739 if origvfs.isfileorlink(f): |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
740 ui.note(_('removing conflicting file: %s\n') |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
741 % origvfs.join(f)) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
742 origvfs.unlink(f) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
743 break |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
744 |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
745 origvfs.makedirs(origbackupdir) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
746 |
35009
99ab7bc944d2
scmutil: don't try to delete origbackup symlinks to directories (issue5731)
Mark Thomas <mbthomas@fb.com>
parents:
34854
diff
changeset
|
747 if origvfs.isdir(filepathfromroot) and not origvfs.islink(filepathfromroot): |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
748 ui.note(_('removing conflicting directory: %s\n') |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
749 % origvfs.join(filepathfromroot)) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
750 origvfs.rmtree(filepathfromroot, forcibly=True) |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
751 |
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
752 return origvfs.join(filepathfromroot) |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
753 |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
754 class _containsnode(object): |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
755 """proxy __contains__(node) to container.__contains__ which accepts revs""" |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
756 |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
757 def __init__(self, repo, revcontainer): |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
758 self._torev = repo.changelog.rev |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
759 self._revcontains = revcontainer.__contains__ |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
760 |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
761 def __contains__(self, node): |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
762 return self._revcontains(self._torev(node)) |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
763 |
34793
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
764 def cleanupnodes(repo, replacements, operation, moves=None, metadata=None): |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
765 """do common cleanups when old nodes are replaced by new nodes |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
766 |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
767 That includes writing obsmarkers or stripping nodes, and moving bookmarks. |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
768 (we might also want to move working directory parent in the future) |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
769 |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
770 By default, bookmark moves are calculated automatically from 'replacements', |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
771 but 'moves' can be used to override that. Also, 'moves' may include |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
772 additional bookmark moves that should not have associated obsmarkers. |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
773 |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
774 replacements is {oldnode: [newnode]} or a iterable of nodes if they do not |
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
775 have replacements. operation is a string, like "rebase". |
34793
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
776 |
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
777 metadata is dictionary containing metadata to be stored in obsmarker if |
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
778 obsolescence is enabled. |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
779 """ |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
780 if not replacements and not moves: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
781 return |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
782 |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
783 # translate mapping's other forms |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
784 if not util.safehasattr(replacements, 'items'): |
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
785 replacements = {n: () for n in replacements} |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
786 |
34352
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
787 # Calculate bookmark movements |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
788 if moves is None: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
789 moves = {} |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
790 # Unfiltered repo is needed since nodes in replacements might be hidden. |
34352
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
791 unfi = repo.unfiltered() |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
792 for oldnode, newnodes in replacements.items(): |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
793 if oldnode in moves: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
794 continue |
34352
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
795 if len(newnodes) > 1: |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
796 # usually a split, take the one with biggest rev number |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
797 newnode = next(unfi.set('max(%ln)', newnodes)).node() |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
798 elif len(newnodes) == 0: |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
799 # move bookmark backwards |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
800 roots = list(unfi.set('max((::%n) - %ln)', oldnode, |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
801 list(replacements))) |
34352
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
802 if roots: |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
803 newnode = roots[0].node() |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
804 else: |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
805 newnode = nullid |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
806 else: |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
807 newnode = newnodes[0] |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
808 moves[oldnode] = newnode |
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
809 |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
810 with repo.transaction('cleanup') as tr: |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
811 # Move bookmarks |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
812 bmarks = repo._bookmarks |
33511
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
813 bmarkchanges = [] |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
814 allnewnodes = [n for ns in replacements.values() for n in ns] |
34352
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33649
diff
changeset
|
815 for oldnode, newnode in moves.items(): |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
816 oldbmarks = repo.nodebookmarks(oldnode) |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
817 if not oldbmarks: |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
818 continue |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
819 from . import bookmarks # avoid import cycle |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
820 repo.ui.debug('moving bookmarks %r from %s to %s\n' % |
36836
a00c38b33047
py3: drop b'' from debug message "moving bookmarks"
Yuya Nishihara <yuya@tcha.org>
parents:
36695
diff
changeset
|
821 (util.rapply(pycompat.maybebytestr, oldbmarks), |
a00c38b33047
py3: drop b'' from debug message "moving bookmarks"
Yuya Nishihara <yuya@tcha.org>
parents:
36695
diff
changeset
|
822 hex(oldnode), hex(newnode))) |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
823 # Delete divergent bookmarks being parents of related newnodes |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
824 deleterevs = repo.revs('parents(roots(%ln & (::%n))) - parents(%n)', |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
825 allnewnodes, newnode, oldnode) |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
826 deletenodes = _containsnode(repo, deleterevs) |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
827 for name in oldbmarks: |
33511
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
828 bmarkchanges.append((name, newnode)) |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
829 for b in bookmarks.divergent2delete(repo, deletenodes, name): |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
830 bmarkchanges.append((b, None)) |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
831 |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
832 if bmarkchanges: |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
833 bmarks.applychanges(repo, tr, bmarkchanges) |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
834 |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
835 # Obsolete or strip nodes |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
836 if obsolete.isenabled(repo, obsolete.createmarkersopt): |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
837 # If a node is already obsoleted, and we want to obsolete it |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
838 # without a successor, skip that obssolete request since it's |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
839 # unnecessary. That's the "if s or not isobs(n)" check below. |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
840 # Also sort the node in topology order, that might be useful for |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
841 # some obsstore logic. |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
842 # NOTE: the filtering and sorting might belong to createmarkers. |
33330
ba43e5ee9c6d
scmutil: make cleanupnodes handle filtered node
Jun Wu <quark@fb.com>
parents:
33252
diff
changeset
|
843 isobs = unfi.obsstore.successors.__contains__ |
ba43e5ee9c6d
scmutil: make cleanupnodes handle filtered node
Jun Wu <quark@fb.com>
parents:
33252
diff
changeset
|
844 torev = unfi.changelog.rev |
ba43e5ee9c6d
scmutil: make cleanupnodes handle filtered node
Jun Wu <quark@fb.com>
parents:
33252
diff
changeset
|
845 sortfunc = lambda ns: torev(ns[0]) |
33352
967ac37f3d45
cleanupnode: do not use generator for node mapping
Octobus <contact@octobus.net>
parents:
33331
diff
changeset
|
846 rels = [(unfi[n], tuple(unfi[m] for m in s)) |
34353
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
34352
diff
changeset
|
847 for n, s in sorted(replacements.items(), key=sortfunc) |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
848 if s or not isobs(n)] |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
849 if rels: |
34793
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
850 obsolete.createmarkers(repo, rels, operation=operation, |
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
851 metadata=metadata) |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
852 else: |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
853 from . import repair # avoid import cycle |
34354
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
854 tostrip = list(replacements) |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
855 if tostrip: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
34353
diff
changeset
|
856 repair.delayedstrip(repo.ui, repo, tostrip, operation) |
33088
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32659
diff
changeset
|
857 |
37269
14cd5290c4e6
addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37259
diff
changeset
|
858 def addremove(repo, matcher, prefix, opts=None): |
26329
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
859 if opts is None: |
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
860 opts = {} |
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
|
861 m = matcher |
37269
14cd5290c4e6
addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37259
diff
changeset
|
862 dry_run = opts.get('dry_run') |
37306
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
863 try: |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
864 similarity = float(opts.get('similarity') or 0) |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
865 except ValueError: |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
866 raise error.Abort(_('similarity must be a number')) |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
867 if similarity < 0 or similarity > 100: |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
868 raise error.Abort(_('similarity must be between 0 and 100')) |
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37271
diff
changeset
|
869 similarity /= 100.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
|
870 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
871 ret = 0 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
872 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
|
873 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
874 wctx = repo[None] |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
875 for subpath in sorted(wctx.substate): |
29802
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29771
diff
changeset
|
876 submatch = matchmod.subdirmatcher(subpath, m) |
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29771
diff
changeset
|
877 if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()): |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
878 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
|
879 try: |
37269
14cd5290c4e6
addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37259
diff
changeset
|
880 if sub.addremove(submatch, prefix, opts): |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
881 ret = 1 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
882 except error.LookupError: |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
883 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
|
884 % join(subpath)) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
885 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
886 rejected = [] |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
887 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
|
888 if f in m.files(): |
25434
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
889 m.bad(f, msg) |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
890 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
|
891 |
25434
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
892 badmatch = matchmod.badmatch(m, badfn) |
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
893 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, |
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
894 badmatch) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
895 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
896 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
|
897 toprint = unknownset.copy() |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
898 toprint.update(deleted) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
899 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
|
900 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
|
901 if abs in unknownset: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
902 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
|
903 else: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
904 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
|
905 repo.ui.status(status) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
906 |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
907 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
|
908 similarity) |
14320 | 909 |
910 if not dry_run: | |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
911 _markchanges(repo, unknown + forgotten, deleted, renames) |
14320 | 912 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
913 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
|
914 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
|
915 return 1 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
916 return ret |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
917 |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
918 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
|
919 '''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
|
920 the repo root.''' |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
921 m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
922 rejected = [] |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
923 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
924 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
|
925 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
926 if repo.ui.verbose: |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 else: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
934 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
|
935 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
|
936 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
937 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
|
938 similarity) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
939 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
940 _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
|
941 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
942 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
|
943 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
|
944 return 1 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
945 return 0 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
946 |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
947 def _interestingfiles(repo, matcher): |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
948 '''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
|
949 about. |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
950 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
951 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
|
952 whether files are modified or clean.''' |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
953 added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
33649
377e8ddaebef
pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents:
33542
diff
changeset
|
954 audit_path = pathutil.pathauditor(repo.root, cached=True) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
955 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
956 ctx = repo[None] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
957 dirstate = repo.dirstate |
34343
255c761a52db
dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents:
34327
diff
changeset
|
958 walkresults = dirstate.walk(matcher, subrepos=sorted(ctx.substate), |
255c761a52db
dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents:
34327
diff
changeset
|
959 unknown=True, ignored=False, full=False) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
960 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
|
961 dstate = dirstate[abs] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
962 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
|
963 unknown.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
964 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
|
965 deleted.append(abs) |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
966 elif dstate == 'r' and st: |
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
967 forgotten.append(abs) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
968 # for finding renames |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
969 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
|
970 removed.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
971 elif dstate == 'a': |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
972 added.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
973 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
974 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
|
975 |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
976 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
|
977 '''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
|
978 renames = {} |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
979 if similarity > 0: |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
980 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
|
981 similarity): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
982 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
|
983 or not matcher.exact(new)): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
984 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
|
985 '(%d%% similar)\n') % |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
986 (matcher.rel(old), matcher.rel(new), |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
987 score * 100)) |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
988 renames[new] = old |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
989 return renames |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
990 |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
991 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
|
992 '''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
|
993 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
|
994 wctx = repo[None] |
27851
4133a306606c
with: use context manager in _markchanges
Bryan O'Sullivan <bryano@fb.com>
parents:
27706
diff
changeset
|
995 with repo.wlock(): |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
996 wctx.forget(deleted) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
997 wctx.add(unknown) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
998 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
|
999 wctx.copy(old, new) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1000 |
14320 | 1001 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
1002 """Update the dirstate to reflect the intent of copying src to dst. For | |
1003 different reasons it might not end with dst being marked as copied from src. | |
1004 """ | |
1005 origsrc = repo.dirstate.copied(src) or src | |
1006 if dst == origsrc: # copying back a copy? | |
1007 if repo.dirstate[dst] not in 'mn' and not dryrun: | |
1008 repo.dirstate.normallookup(dst) | |
1009 else: | |
1010 if repo.dirstate[origsrc] == 'a' and origsrc == src: | |
1011 if not ui.quiet: | |
1012 ui.warn(_("%s has not been committed yet, so no copy " | |
1013 "data will be stored for %s.\n") | |
1014 % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd))) | |
1015 if repo.dirstate[dst] in '?r' and not dryrun: | |
1016 wctx.add([dst]) | |
1017 elif not dryrun: | |
1018 wctx.copy(origsrc, dst) | |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1019 |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1020 def readrequires(opener, supported): |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1021 '''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
|
1022 are in the list of supported features.''' |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1023 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
|
1024 missings = [] |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1025 for r in requirements: |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1026 if r not in supported: |
36313
3f98634b6572
scmutil: fix requires-file isalnum() check on first byte
Augie Fackler <augie@google.com>
parents:
36262
diff
changeset
|
1027 if not r or not r[0:1].isalnum(): |
14484
4582a4dd1817
requires: note apparent corruption
Matt Mackall <mpm@selenic.com>
parents:
14483
diff
changeset
|
1028 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
|
1029 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
|
1030 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
|
1031 if missings: |
16683 | 1032 raise error.RequirementError( |
20820
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
1033 _("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
|
1034 % " ".join(missings), |
26421
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
26329
diff
changeset
|
1035 hint=_("see https://mercurial-scm.org/wiki/MissingRequirement" |
20820
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
1036 " for more information")) |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1037 return requirements |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1038 |
24934
5abd0a76bc8f
requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents:
24755
diff
changeset
|
1039 def writerequires(opener, requirements): |
27706
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
1040 with opener('requires', 'w') as fp: |
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
1041 for r in sorted(requirements): |
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
1042 fp.write("%s\n" % r) |
24934
5abd0a76bc8f
requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents:
24755
diff
changeset
|
1043 |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1044 class filecachesubentry(object): |
20042
9a72d3886888
scmutil.filecacheentry: make stat argument to constructor mandatory
Siddharth Agarwal <sid0@fb.com>
parents:
20033
diff
changeset
|
1045 def __init__(self, path, stat): |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1046 self.path = path |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1047 self.cachestat = None |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1048 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1049 |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1050 if stat: |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1051 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
|
1052 |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1053 if self.cachestat: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1054 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
|
1055 else: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1056 # 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
|
1057 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1058 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1059 def refresh(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1060 if self.cacheable(): |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1061 self.cachestat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1062 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1063 def cacheable(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1064 if self._cacheable is not None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1065 return self._cacheable |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1066 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1067 # we don't know yet, assume it is for now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1068 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1069 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1070 def changed(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1071 # no point in going further if we can't cache it |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1072 if not self.cacheable(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1073 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1074 |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1075 newstat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1076 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1077 # 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
|
1078 if newstat and self._cacheable is None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1079 self._cacheable = newstat.cacheable() |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1080 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1081 # check again |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1082 if not self._cacheable: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1083 return True |
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 if self.cachestat != newstat: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1086 self.cachestat = newstat |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1087 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1088 else: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1089 return False |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1090 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1091 @staticmethod |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1092 def stat(path): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1093 try: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1094 return util.cachestat(path) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25658
diff
changeset
|
1095 except OSError as e: |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1096 if e.errno != errno.ENOENT: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1097 raise |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1098 |
20044
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1099 class filecacheentry(object): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1100 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
|
1101 self._entries = [] |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1102 for path in paths: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1103 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
|
1104 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1105 def changed(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1106 '''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
|
1107 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1108 if entry.changed(): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1109 return True |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1110 return False |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1111 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1112 def refresh(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1113 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1114 entry.refresh() |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1115 |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1116 class filecache(object): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1117 '''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
|
1118 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1119 Records stat info when called in _filecache. |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1120 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1121 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
|
1122 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
|
1123 _filecache. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1124 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1125 Mercurial either atomic renames or appends for files under .hg, |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1126 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
|
1127 to tell us if a file has been replaced. If it can't, we fallback to |
26098 | 1128 recreating the object on every call (essentially the same behavior as |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1129 propertycache). |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1130 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1131 ''' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1132 def __init__(self, *paths): |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1133 self.paths = paths |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1134 |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1135 def join(self, obj, fname): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1136 """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
|
1137 |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1138 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
|
1139 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
|
1140 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
|
1141 """ |
31285
1937671105bc
filecache: make 'join' abstract
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31217
diff
changeset
|
1142 raise NotImplementedError |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1143 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1144 def __call__(self, func): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1145 self.func = func |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1146 self.sname = func.__name__ |
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1147 self.name = pycompat.sysbytes(self.sname) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1148 return self |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1149 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1150 def __get__(self, obj, type=None): |
29373
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1151 # if accessed on the class, return the descriptor itself. |
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1152 if obj is None: |
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1153 return self |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1154 # do we need to check if the file changed? |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1155 if self.sname 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
|
1156 assert self.name in obj._filecache, self.name |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1157 return obj.__dict__[self.sname] |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1158 |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1159 entry = obj._filecache.get(self.name) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1160 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1161 if entry: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1162 if entry.changed(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1163 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1164 else: |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1165 paths = [self.join(obj, path) for path in self.paths] |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1166 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1167 # 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
|
1168 # 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
|
1169 entry = filecacheentry(paths, True) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1170 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1171 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1172 obj._filecache[self.name] = entry |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1173 |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1174 obj.__dict__[self.sname] = entry.obj |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1175 return entry.obj |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1176 |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1177 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
|
1178 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
|
1179 # 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
|
1180 # implies X in _filecache |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1181 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
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1187 ce.obj = value # update cached copy |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1188 obj.__dict__[self.sname] = value # update copy returned by obj.x |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1189 |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1190 def __delete__(self, obj): |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1191 try: |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1192 del obj.__dict__[self.sname] |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1193 except KeyError: |
37869
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37868
diff
changeset
|
1194 raise AttributeError(self.sname) |
26490
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1195 |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1196 def extdatasource(repo, source): |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1197 """Gather a map of rev -> value dict from the specified source |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1198 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1199 A source spec is treated as a URL, with a special case shell: type |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1200 for parsing the output from a shell command. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1201 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1202 The data is parsed as a series of newline-separated records where |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1203 each record is a revision specifier optionally followed by a space |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1204 and a freeform string value. If the revision is known locally, it |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1205 is converted to a rev, otherwise the record is skipped. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1206 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1207 Note that both key and value are treated as UTF-8 and converted to |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1208 the local encoding. This allows uniformity between local and |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1209 remote data sources. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1210 """ |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1211 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1212 spec = repo.ui.config("extdata", source) |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1213 if not spec: |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1214 raise error.Abort(_("unknown extdata source '%s'") % source) |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1215 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1216 data = {} |
34461
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1217 src = proc = None |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1218 try: |
34461
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1219 if spec.startswith("shell:"): |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1220 # external commands should be run relative to the repo root |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1221 cmd = spec[6:] |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1222 proc = subprocess.Popen(cmd, shell=True, bufsize=-1, |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37094
diff
changeset
|
1223 close_fds=procutil.closefds, |
34461
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1224 stdout=subprocess.PIPE, cwd=repo.root) |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1225 src = proc.stdout |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1226 else: |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1227 # treat as a URL or file |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1228 src = url.open(repo.ui, spec) |
34460
910adadf08e8
extdata: just use iterator to read lines one by one
Yuya Nishihara <yuya@tcha.org>
parents:
34459
diff
changeset
|
1229 for l in src: |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1230 if " " in l: |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1231 k, v = l.strip().split(" ", 1) |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1232 else: |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1233 k, v = l.strip(), "" |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1234 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1235 k = encoding.tolocal(k) |
34459
d5c5cc767b7e
extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents:
34456
diff
changeset
|
1236 try: |
37360
d0d55980ffa7
extdatasource: use revsymbol() for converting to node
Martin von Zweigbergk <martinvonz@google.com>
parents:
37350
diff
changeset
|
1237 data[revsingle(repo, k).rev()] = encoding.tolocal(v) |
34459
d5c5cc767b7e
extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents:
34456
diff
changeset
|
1238 except (error.LookupError, error.RepoLookupError): |
d5c5cc767b7e
extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents:
34456
diff
changeset
|
1239 pass # we ignore data for nodes that don't exist locally |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1240 finally: |
34461
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1241 if proc: |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1242 proc.communicate() |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1243 if src: |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1244 src.close() |
35412
b1959391a088
extdata: abort if external command exits with non-zero status (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
35308
diff
changeset
|
1245 if proc and proc.returncode != 0: |
b1959391a088
extdata: abort if external command exits with non-zero status (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
35308
diff
changeset
|
1246 raise error.Abort(_("extdata command '%s' failed: %s") |
37463
bbd240f81ac5
procutil: make explainexit() simply return a message (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37385
diff
changeset
|
1247 % (cmd, procutil.explainexit(proc.returncode))) |
34456
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1248 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1249 return data |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34367
diff
changeset
|
1250 |
26490
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1251 def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1252 if lock is None: |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1253 raise error.LockInheritanceContractViolation( |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1254 'lock can only be inherited while held') |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1255 if environ is None: |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1256 environ = {} |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1257 with lock.inherit() as locker: |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1258 environ[envvar] = locker |
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
1259 return repo.ui.system(cmd, environ=environ, *args, **kwargs) |
26491
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1260 |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1261 def wlocksub(repo, cmd, *args, **kwargs): |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1262 """run cmd as a subprocess that allows inheriting repo's wlock |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1263 |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1264 This can only be called while the wlock is held. This takes all the |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1265 arguments that ui.system does, and returns the exit code of the |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1266 subprocess.""" |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1267 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args, |
366d489295ca
scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents:
26490
diff
changeset
|
1268 **kwargs) |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1269 |
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1270 def gdinitconfig(ui): |
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1271 """helper function to know if a repo should be created as general delta |
26907
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1272 """ |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1273 # experimental config: format.generaldelta |
33238
784f2bd96d43
configitems: register the 'format.generaldelta' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33088
diff
changeset
|
1274 return (ui.configbool('format', 'generaldelta') |
33246
4d9458e06ef0
configitems: register the 'format.usegeneraldelta' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33238
diff
changeset
|
1275 or ui.configbool('format', 'usegeneraldelta')) |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1276 |
26907
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1277 def gddeltaconfig(ui): |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1278 """helper function to know if incoming delta should be optimised |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1279 """ |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1280 # experimental config: format.generaldelta |
33238
784f2bd96d43
configitems: register the 'format.generaldelta' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33088
diff
changeset
|
1281 return ui.configbool('format', 'generaldelta') |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1282 |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1283 class simplekeyvaluefile(object): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1284 """A simple file with key=value lines |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1285 |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1286 Keys must be alphanumerics and start with a letter, values must not |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1287 contain '\n' characters""" |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1288 firstlinekey = '__firstline' |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1289 |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1290 def __init__(self, vfs, path, keys=None): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1291 self.vfs = vfs |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1292 self.path = path |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1293 |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1294 def read(self, firstlinenonkeyval=False): |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1295 """Read the contents of a simple key-value file |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1296 |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1297 'firstlinenonkeyval' indicates whether the first line of file should |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1298 be treated as a key-value pair or reuturned fully under the |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1299 __firstline key.""" |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1300 lines = self.vfs.readlines(self.path) |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1301 d = {} |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1302 if firstlinenonkeyval: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1303 if not lines: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1304 e = _("empty simplekeyvalue file") |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1305 raise error.CorruptedState(e) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1306 # we don't want to include '\n' in the __firstline |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1307 d[self.firstlinekey] = lines[0][:-1] |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1308 del lines[0] |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1309 |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1310 try: |
32269
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32172
diff
changeset
|
1311 # the 'if line.strip()' part prevents us from failing on empty |
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32172
diff
changeset
|
1312 # lines which only contain '\n' therefore are not skipped |
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32172
diff
changeset
|
1313 # by 'if line' |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1314 updatedict = dict(line[:-1].split('=', 1) for line in lines |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1315 if line.strip()) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1316 if self.firstlinekey in updatedict: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1317 e = _("%r can't be used as a key") |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1318 raise error.CorruptedState(e % self.firstlinekey) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1319 d.update(updatedict) |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1320 except ValueError as e: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1321 raise error.CorruptedState(str(e)) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1322 return d |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1323 |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1324 def write(self, data, firstline=None): |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1325 """Write key=>value mapping to a file |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1326 data is a dict. Keys must be alphanumerical and start with a letter. |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1327 Values must not contain newline characters. |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1328 |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1329 If 'firstline' is not None, it is written to file before |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1330 everything else, as it is, not in a key=value form""" |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1331 lines = [] |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1332 if firstline is not None: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1333 lines.append('%s\n' % firstline) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1334 |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1335 for k, v in data.items(): |
32270
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1336 if k == self.firstlinekey: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1337 e = "key name '%s' is reserved" % self.firstlinekey |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32269
diff
changeset
|
1338 raise error.ProgrammingError(e) |
35913
558e01a23f40
py3: slice on bytes to prevent getting the ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35888
diff
changeset
|
1339 if not k[0:1].isalpha(): |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1340 e = "keys must start with a letter in a key-value file" |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1341 raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1342 if not k.isalnum(): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1343 e = "invalid key name in a simple key-value file" |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1344 raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1345 if '\n' in v: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1346 e = "invalid value in a simple key-value file" |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1347 raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1348 lines.append("%s=%s\n" % (k, v)) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1349 with self.vfs(self.path, mode='wb', atomictemp=True) as fp: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
1350 fp.write(''.join(lines)) |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1351 |
33541
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1352 _reportobsoletedsource = [ |
33542
b11e8c67fb0f
debugobsolete: also report the number of obsoleted changesets
Boris Feld <boris.feld@octobus.net>
parents:
33541
diff
changeset
|
1353 'debugobsolete', |
33541
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1354 'pull', |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1355 'push', |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1356 'serve', |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1357 'unbundle', |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1358 ] |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1359 |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1360 _reportnewcssource = [ |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1361 'pull', |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1362 'unbundle', |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1363 ] |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1364 |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1365 def prefetchfiles(repo, revs, match): |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1366 """Invokes the registered file prefetch functions, allowing extensions to |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1367 ensure the corresponding files are available locally, before the command |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1368 uses them.""" |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1369 if match: |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1370 # The command itself will complain about files that don't exist, so |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1371 # don't duplicate the message. |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1372 match = matchmod.badmatch(match, lambda fn, msg: None) |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1373 else: |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1374 match = matchall(repo) |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1375 |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1376 fileprefetchhooks(repo, revs, match) |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1377 |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1378 # a list of (repo, revs, match) prefetch functions |
36137
f52a9336ac5f
cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
35913
diff
changeset
|
1379 fileprefetchhooks = util.hooks() |
f52a9336ac5f
cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
35913
diff
changeset
|
1380 |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1381 # A marker that tells the evolve extension to suppress its own reporting |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1382 _reportstroubledchangesets = True |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1383 |
33541
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1384 def registersummarycallback(repo, otr, txnname=''): |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1385 """register a callback to issue a summary after the transaction is closed |
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1386 """ |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1387 def txmatch(sources): |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1388 return any(txnname.startswith(source) for source in sources) |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1389 |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1390 categories = [] |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1391 |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1392 def reportsummary(func): |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1393 """decorator for report callbacks.""" |
35035
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1394 # The repoview life cycle is shorter than the one of the actual |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1395 # underlying repository. So the filtered object can die before the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1396 # weakref is used leading to troubles. We keep a reference to the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1397 # unfiltered object and restore the filtering when retrieving the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1398 # repository through the weakref. |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1399 filtername = repo.filtername |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1400 reporef = weakref.ref(repo.unfiltered()) |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1401 def wrapped(tr): |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1402 repo = reporef() |
35035
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1403 if filtername: |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
35009
diff
changeset
|
1404 repo = repo.filtered(filtername) |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1405 func(repo, tr) |
35748
963a611b2f39
scmutil: 0-pad transaction report callback category
Martin von Zweigbergk <martinvonz@google.com>
parents:
35710
diff
changeset
|
1406 newcat = '%02i-txnreport' % len(categories) |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1407 otr.addpostclose(newcat, wrapped) |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1408 categories.append(newcat) |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1409 return wrapped |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1410 |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1411 if txmatch(_reportobsoletedsource): |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1412 @reportsummary |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1413 def reportobsoleted(repo, tr): |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1414 obsoleted = obsutil.getobsoleted(repo, tr) |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1415 if obsoleted: |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1416 repo.ui.status(_('obsoleted %i changesets\n') |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1417 % len(obsoleted)) |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1418 |
35710
5cd60b0587a8
evolution: make reporting of new unstable changesets optional
Martin von Zweigbergk <martinvonz@google.com>
parents:
35709
diff
changeset
|
1419 if (obsolete.isenabled(repo, obsolete.createmarkersopt) and |
5cd60b0587a8
evolution: make reporting of new unstable changesets optional
Martin von Zweigbergk <martinvonz@google.com>
parents:
35709
diff
changeset
|
1420 repo.ui.configbool('experimental', 'evolution.report-instabilities')): |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1421 instabilitytypes = [ |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1422 ('orphan', 'orphan'), |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1423 ('phase-divergent', 'phasedivergent'), |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1424 ('content-divergent', 'contentdivergent'), |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1425 ] |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1426 |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1427 def getinstabilitycounts(repo): |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1428 filtered = repo.changelog.filteredrevs |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1429 counts = {} |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1430 for instability, revset in instabilitytypes: |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1431 counts[instability] = len(set(obsolete.getrevs(repo, revset)) - |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1432 filtered) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1433 return counts |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1434 |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1435 oldinstabilitycounts = getinstabilitycounts(repo) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1436 @reportsummary |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1437 def reportnewinstabilities(repo, tr): |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1438 newinstabilitycounts = getinstabilitycounts(repo) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1439 for instability, revset in instabilitytypes: |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1440 delta = (newinstabilitycounts[instability] - |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1441 oldinstabilitycounts[instability]) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1442 if delta > 0: |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1443 repo.ui.warn(_('%i new %s changesets\n') % |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1444 (delta, instability)) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35499
diff
changeset
|
1445 |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1446 if txmatch(_reportnewcssource): |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1447 @reportsummary |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1448 def reportnewcs(repo, tr): |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1449 """Report the range of new revisions pulled/unbundled.""" |
35308
137a08d82232
transaction: build changes['revs'] as range instead of a set
Joerg Sonnenberger <joerg@bec.de>
parents:
35206
diff
changeset
|
1450 newrevs = tr.changes.get('revs', xrange(0, 0)) |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1451 if not newrevs: |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1452 return |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1453 |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1454 # Compute the bounds of new revisions' range, excluding obsoletes. |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1455 unfi = repo.unfiltered() |
34737
0c06875e7755
transaction-summary: use a revset to filter obsoletes in reportnewcs()
Denis Laxalde <denis@laxalde.org>
parents:
34661
diff
changeset
|
1456 revs = unfi.revs('%ld and not obsolete()', newrevs) |
0c06875e7755
transaction-summary: use a revset to filter obsoletes in reportnewcs()
Denis Laxalde <denis@laxalde.org>
parents:
34661
diff
changeset
|
1457 if not revs: |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1458 # Got only obsoletes. |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1459 return |
34737
0c06875e7755
transaction-summary: use a revset to filter obsoletes in reportnewcs()
Denis Laxalde <denis@laxalde.org>
parents:
34661
diff
changeset
|
1460 minrev, maxrev = repo[revs.min()], repo[revs.max()] |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1461 |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1462 if minrev == maxrev: |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1463 revrange = minrev |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1464 else: |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1465 revrange = '%s:%s' % (minrev, maxrev) |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1466 repo.ui.status(_('new changesets %s\n') % revrange) |
35177
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1467 |
35184
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35177
diff
changeset
|
1468 def nodesummaries(repo, nodes, maxnumnodes=4): |
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35177
diff
changeset
|
1469 if len(nodes) <= maxnumnodes or repo.ui.verbose: |
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35177
diff
changeset
|
1470 return ' '.join(short(h) for h in nodes) |
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35177
diff
changeset
|
1471 first = ' '.join(short(h) for h in nodes[:maxnumnodes]) |
35206
278f1feee73a
scmutil: improve format pattern used in nodesummaries
Boris Feld <boris.feld@octobus.net>
parents:
35185
diff
changeset
|
1472 return _("%s and %d others") % (first, len(nodes) - maxnumnodes) |
35184
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35177
diff
changeset
|
1473 |
35185
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1474 def enforcesinglehead(repo, tr, desc): |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1475 """check that no named branch has multiple heads""" |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1476 if desc in ('strip', 'repair'): |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1477 # skip the logic during strip |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1478 return |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1479 visible = repo.filtered('visible') |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1480 # possible improvement: we could restrict the check to affected branch |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1481 for name, heads in visible.branchmap().iteritems(): |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1482 if len(heads) > 1: |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1483 msg = _('rejecting multiple heads on branch "%s"') |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1484 msg %= name |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1485 hint = _('%d heads: %s') |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1486 hint %= (len(heads), nodesummaries(repo, heads)) |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1487 raise error.Abort(msg, hint=hint) |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35184
diff
changeset
|
1488 |
35177
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1489 def wrapconvertsink(sink): |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1490 """Allow extensions to wrap the sink returned by convcmd.convertsink() |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1491 before it is used, whether or not the convert extension was formally loaded. |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1492 """ |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35035
diff
changeset
|
1493 return sink |
35496
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1494 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1495 def unhidehashlikerevs(repo, specs, hiddentype): |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1496 """parse the user specs and unhide changesets whose hash or revision number |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1497 is passed. |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1498 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1499 hiddentype can be: 1) 'warn': warn while unhiding changesets |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1500 2) 'nowarn': don't warn while unhiding changesets |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1501 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1502 returns a repo object with the required changesets unhidden |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1503 """ |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1504 if not repo.filtername or not repo.ui.configbool('experimental', |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1505 'directaccess'): |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1506 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1507 |
35499
b55a142f00c5
scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35496
diff
changeset
|
1508 if repo.filtername not in ('visible', 'visible-hidden'): |
35496
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1509 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1510 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1511 symbols = set() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1512 for spec in specs: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1513 try: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1514 tree = revsetlang.parse(spec) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1515 except error.ParseError: # will be reported by scmutil.revrange() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1516 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1517 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1518 symbols.update(revsetlang.gethashlikesymbols(tree)) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1519 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1520 if not symbols: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1521 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1522 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1523 revs = _getrevsfromsymbols(repo, symbols) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1524 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1525 if not revs: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1526 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1527 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1528 if hiddentype == 'warn': |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1529 unfi = repo.unfiltered() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1530 revstr = ", ".join([pycompat.bytestr(unfi[l]) for l in revs]) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1531 repo.ui.warn(_("warning: accessing hidden changesets for write " |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1532 "operation: %s\n") % revstr) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1533 |
35499
b55a142f00c5
scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35496
diff
changeset
|
1534 # we have to use new filtername to separate branch/tags cache until we can |
b55a142f00c5
scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35496
diff
changeset
|
1535 # disbale these cache when revisions are dynamically pinned. |
35496
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1536 return repo.filtered('visible-hidden', revs) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1537 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1538 def _getrevsfromsymbols(repo, symbols): |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1539 """parse the list of symbols and returns a set of revision numbers of hidden |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1540 changesets present in symbols""" |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1541 revs = set() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1542 unfi = repo.unfiltered() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1543 unficl = unfi.changelog |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1544 cl = repo.changelog |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1545 tiprev = len(unficl) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1546 allowrevnums = repo.ui.configbool('experimental', 'directaccess.revnums') |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1547 for s in symbols: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1548 try: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1549 n = int(s) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1550 if n <= tiprev: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1551 if not allowrevnums: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1552 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1553 else: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1554 if n not in cl: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1555 revs.add(n) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1556 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1557 except ValueError: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1558 pass |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1559 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1560 try: |
37868
69de3c3de036
directaccess: use resolvehexnodeidprefix() instead of _partialmatch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37865
diff
changeset
|
1561 s = resolvehexnodeidprefix(unfi, s) |
37094
7f025c9b7865
directaccess: do not abort by 'ff...' hash
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
1562 except (error.LookupError, error.WdirUnsupported): |
35496
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1563 s = None |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1564 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1565 if s is not None: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1566 rev = unficl.rev(s) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1567 if rev not in cl: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1568 revs.add(rev) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1569 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35412
diff
changeset
|
1570 return revs |