author | Wagner Bruna <wbruna@softwareexpress.com.br> |
Wed, 31 May 2017 19:24:00 -0300 | |
branch | stable |
changeset 32574 | 870248603a4e |
parent 32088 | 0d892d820a51 |
child 32111 | 1208b74841ff |
child 33633 | 20bac46f7744 |
permissions | -rw-r--r-- |
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 |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
16 |
|
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
17 |
from .i18n import _ |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
18 |
from .node import wdirrev |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
19 |
from . import ( |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
20 |
encoding, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
21 |
error, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
22 |
match as matchmod, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
23 |
pathutil, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
24 |
phases, |
30305
af7c60988f6e
py3: make scmutil.rcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30109
diff
changeset
|
25 |
pycompat, |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
26 |
revsetlang, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
27 |
similar, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
28 |
util, |
31217
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
29 |
vfs as vfsmod, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
30 |
) |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
31 |
|
30639
d524c88511a7
py3: replace os.name with pycompat.osname (part 1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30520
diff
changeset
|
32 |
if pycompat.osname == 'nt': |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
33 |
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
|
34 |
else: |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
35 |
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
|
36 |
|
30314
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30309
diff
changeset
|
37 |
termsize = scmplatform.termsize |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
38 |
|
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
39 |
class status(tuple): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
40 |
'''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
|
41 |
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
|
42 |
''' |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
43 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
44 |
__slots__ = () |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
45 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
46 |
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
|
47 |
clean): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
48 |
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
|
49 |
ignored, clean)) |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
50 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
51 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
52 |
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
|
53 |
'''files that have been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
54 |
return self[0] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
55 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
56 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
57 |
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
|
58 |
'''files that have been added''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
59 |
return self[1] |
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 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
62 |
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
|
63 |
'''files that have been removed''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
64 |
return self[2] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
65 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
66 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
67 |
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
|
68 |
'''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
|
69 |
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
|
70 |
''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
71 |
return self[3] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
72 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
73 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
74 |
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
|
75 |
'''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
|
76 |
return self[4] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
77 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
78 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
79 |
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
|
80 |
'''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
|
81 |
return self[5] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
82 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
83 |
@property |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
84 |
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
|
85 |
'''files that have not been modified''' |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
86 |
return self[6] |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
87 |
|
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
88 |
def __repr__(self, *args, **kwargs): |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
89 |
return (('<status modified=%r, added=%r, removed=%r, deleted=%r, ' |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
90 |
'unknown=%r, ignored=%r, clean=%r>') % self) |
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
91 |
|
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
92 |
def itersubrepos(ctx1, ctx2): |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
93 |
"""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
|
94 |
# 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
|
95 |
# 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
|
96 |
# 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
|
97 |
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
|
98 |
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
|
99 |
|
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
100 |
missing = set() |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
101 |
|
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
del subpaths[subpath] |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
105 |
missing.add(subpath) |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
106 |
|
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
|
25418
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
110 |
# 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
|
111 |
# 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
|
112 |
# '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
|
113 |
# against itself. |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
114 |
for subpath in missing: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
115 |
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
|
116 |
|
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
117 |
def nochangesfound(ui, repo, excluded=None): |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
118 |
'''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
|
119 |
nodes excluded from the push/pull. |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
120 |
''' |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
121 |
secretlist = [] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
122 |
if excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
123 |
for n in excluded: |
18617
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
124 |
if n not in repo: |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
125 |
# discovery should not have included the filtered revision, |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
126 |
# we have to explicitly exclude it until discovery is cleanup. |
227479f61db9
outgoing: fix possible filtering crash in outgoing (issue3814)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18466
diff
changeset
|
127 |
continue |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
128 |
ctx = repo[n] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
129 |
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
|
130 |
secretlist.append(n) |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
131 |
|
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
132 |
if secretlist: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
133 |
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
|
134 |
% len(secretlist)) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
135 |
else: |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
136 |
ui.status(_("no changes found\n")) |
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
137 |
|
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
138 |
def callcatch(ui, func): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
139 |
"""call func() with global exception handling |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
140 |
|
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
""" |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
144 |
try: |
32041
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
145 |
try: |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
146 |
return func() |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
147 |
except: # re-raises |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
148 |
ui.traceback() |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
149 |
raise |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
150 |
# Global exception handling, alphabetically |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
151 |
# 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
|
152 |
except error.LockHeld as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
else: |
32088
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
156 |
reason = _('lock held by %r') % inst.locker |
30520
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
157 |
ui.warn(_("abort: %s: %s\n") % (inst.desc or 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
|
158 |
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
|
159 |
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
|
160 |
except error.LockUnavailable as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
161 |
ui.warn(_("abort: could not lock %s: %s\n") % |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
162 |
(inst.desc or inst.filename, inst.strerror)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
163 |
except error.OutOfBandError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
164 |
if inst.args: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
165 |
msg = _("abort: remote error:\n") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
166 |
else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
167 |
msg = _("abort: remote error\n") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
168 |
ui.warn(msg) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
169 |
if inst.args: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
170 |
ui.warn(''.join(inst.args)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
171 |
if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
172 |
ui.warn('(%s)\n' % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
173 |
except error.RepoError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
174 |
ui.warn(_("abort: %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
175 |
if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
176 |
ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
177 |
except error.ResponseError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
178 |
ui.warn(_("abort: %s") % inst.args[0]) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
179 |
if not isinstance(inst.args[1], basestring): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
180 |
ui.warn(" %r\n" % (inst.args[1],)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
181 |
elif not inst.args[1]: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
182 |
ui.warn(_(" empty string\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 |
ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
185 |
except error.CensoredNodeError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
186 |
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
|
187 |
except error.RevlogError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
188 |
ui.warn(_("abort: %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
189 |
except error.SignalInterrupt: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
190 |
ui.warn(_("killed!\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
191 |
except error.InterventionRequired as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
192 |
ui.warn("%s\n" % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
193 |
if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
194 |
ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
195 |
return 1 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
196 |
except error.Abort as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
197 |
ui.warn(_("abort: %s\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
198 |
if inst.hint: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
199 |
ui.warn(_("(%s)\n") % inst.hint) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
200 |
except ImportError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
201 |
ui.warn(_("abort: %s!\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
202 |
m = str(inst).split()[-1] |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
203 |
if m in "mpatch bdiff".split(): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
204 |
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
|
205 |
elif m in "zlib".split(): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
206 |
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
|
207 |
except IOError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
208 |
if util.safehasattr(inst, "code"): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
209 |
ui.warn(_("abort: %s\n") % inst) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
210 |
elif util.safehasattr(inst, "reason"): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
211 |
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
|
212 |
reason = inst.reason.args[1] |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
213 |
except (AttributeError, IndexError): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
214 |
# 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
|
215 |
reason = inst.reason |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
216 |
if isinstance(reason, unicode): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
217 |
# SSLError of Python 2.7.9 contains a unicode |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
218 |
reason = reason.encode(encoding.encoding, 'replace') |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
219 |
ui.warn(_("abort: error: %s\n") % reason) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
220 |
elif (util.safehasattr(inst, "args") |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
221 |
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
|
222 |
pass |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
223 |
elif getattr(inst, "strerror", None): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
224 |
if getattr(inst, "filename", None): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
225 |
ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
226 |
else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
227 |
ui.warn(_("abort: %s\n") % inst.strerror) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
228 |
else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
229 |
raise |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
230 |
except OSError as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
231 |
if getattr(inst, "filename", None) is not None: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
232 |
ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename)) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
233 |
else: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
234 |
ui.warn(_("abort: %s\n") % inst.strerror) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
235 |
except MemoryError: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
236 |
ui.warn(_("abort: out of memory\n")) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
237 |
except SystemExit as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
238 |
# 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
|
239 |
# 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
|
240 |
return inst.code |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
241 |
except socket.error as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
242 |
ui.warn(_("abort: %s\n") % inst.args[-1]) |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
243 |
|
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
244 |
return -1 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30417
diff
changeset
|
245 |
|
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
246 |
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
|
247 |
# 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
|
248 |
# 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
|
249 |
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
|
250 |
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
|
251 |
for c in (':', '\0', '\n', '\r'): |
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
252 |
if c in lbl: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
253 |
raise error.Abort(_("%r cannot be used in a name") % c) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
254 |
try: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
255 |
int(lbl) |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26491
diff
changeset
|
256 |
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
|
257 |
except ValueError: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
258 |
pass |
17817
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
259 |
|
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
260 |
def checkfilename(f): |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
261 |
'''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
|
262 |
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
|
263 |
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
|
264 |
|
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
265 |
def checkportable(ui, f): |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
266 |
'''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
|
267 |
checkfilename(f) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
268 |
abort, warn = checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
269 |
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
|
270 |
msg = util.checkwinfilename(f) |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
271 |
if msg: |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
272 |
msg = "%s: %r" % (msg, f) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
273 |
if abort: |
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(msg) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
275 |
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
|
276 |
|
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
277 |
def checkportabilityalert(ui): |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
278 |
'''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
|
279 |
non-portable filenames''' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
280 |
val = ui.config('ui', 'portablefilenames', 'warn') |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
281 |
lval = val.lower() |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
282 |
bval = util.parsebool(val) |
30639
d524c88511a7
py3: replace os.name with pycompat.osname (part 1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30520
diff
changeset
|
283 |
abort = pycompat.osname == 'nt' or lval == 'abort' |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
284 |
warn = bval or lval == 'warn' |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
285 |
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
|
286 |
raise error.ConfigError( |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
287 |
_("ui.portablefilenames value is invalid ('%s')") % val) |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
288 |
return abort, warn |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
289 |
|
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
290 |
class casecollisionauditor(object): |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
291 |
def __init__(self, ui, abort, dirstate): |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
292 |
self._ui = ui |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
293 |
self._abort = abort |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
294 |
allfiles = '\0'.join(dirstate._map) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
295 |
self._loweredfiles = set(encoding.lower(allfiles).split('\0')) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
296 |
self._dirstate = dirstate |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
297 |
# 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
|
298 |
# 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
|
299 |
# same filename twice. |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
300 |
self._newfiles = set() |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
301 |
|
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
msg = _('possible case-folding collision for %s') % f |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
308 |
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
|
309 |
raise error.Abort(msg) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
310 |
self._ui.warn(_("warning: %s\n") % msg) |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
311 |
self._loweredfiles.add(fl) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
312 |
self._newfiles.add(f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
313 |
|
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
314 |
def filteredhash(repo, maxrev): |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
315 |
"""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
|
316 |
|
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
tipnode changing. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
322 |
|
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
323 |
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
|
324 |
that SHA-1 digest. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
325 |
""" |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
326 |
cl = repo.changelog |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
327 |
if not cl.filteredrevs: |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
328 |
return None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
329 |
key = None |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
330 |
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
|
331 |
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
|
332 |
s = hashlib.sha1() |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
333 |
for rev in revs: |
31349
719e64bf9ec2
scmutil: fix key generation to portably bytestringify integer
Augie Fackler <augie@google.com>
parents:
31285
diff
changeset
|
334 |
s.update('%d;' % rev) |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
335 |
key = s.digest() |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
336 |
return key |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
337 |
|
31951
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
338 |
def _deprecated(old, new, func): |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
339 |
msg = ('class at mercurial.scmutil.%s moved to mercurial.vfs.%s' |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
340 |
% (old, new)) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
341 |
def wrapper(*args, **kwargs): |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
342 |
util.nouideprecwarn(msg, '4.2') |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
343 |
return func(*args, **kwargs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
344 |
return wrapper |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
345 |
|
31217
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
346 |
# compatibility layer since all 'vfs' code moved to 'mercurial.vfs' |
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
347 |
# |
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
348 |
# This is hard to instal deprecation warning to this since we do not have |
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
349 |
# access to a 'ui' object. |
31951
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
350 |
opener = _deprecated('opener', 'vfs', vfsmod.vfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
351 |
vfs = _deprecated('vfs', 'vfs', vfsmod.vfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
352 |
filteropener = _deprecated('filteropener', 'filtervfs', vfsmod.filtervfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
353 |
filtervfs = _deprecated('filtervfs', 'filtervfs', vfsmod.filtervfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
354 |
abstractvfs = _deprecated('abstractvfs', 'abstractvfs', vfsmod.abstractvfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
355 |
readonlyvfs = _deprecated('readonlyvfs', 'readonlyvfs', vfsmod.readonlyvfs) |
f23d579a5a04
vfs: deprecate all old classes in scmutil
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31679
diff
changeset
|
356 |
auditvfs = _deprecated('auditvfs', 'auditvfs', vfsmod.auditvfs) |
31217
0f31830fbfc4
vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31025
diff
changeset
|
357 |
checkambigatclosing = vfsmod.checkambigatclosing |
18213
c38a62af000e
vfs: add a read only vfs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18206
diff
changeset
|
358 |
|
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
359 |
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
|
360 |
'''yield every hg repository under path, always recursively. |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
17037
diff
changeset
|
361 |
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
|
362 |
def errhandler(err): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
363 |
if err.filename == path: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
364 |
raise err |
14961
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
365 |
samestat = getattr(os.path, 'samestat', None) |
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
366 |
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
|
367 |
def adddir(dirlst, dirname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
368 |
match = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
369 |
dirstat = os.stat(dirname) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
370 |
for lstdirstat in dirlst: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
371 |
if samestat(dirstat, lstdirstat): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
372 |
match = True |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
373 |
break |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
374 |
if not match: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
375 |
dirlst.append(dirstat) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
376 |
return not match |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
377 |
else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
378 |
followsym = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
379 |
|
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
380 |
if (seen_dirs is None) and followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
381 |
seen_dirs = [] |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
382 |
adddir(seen_dirs, path) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
383 |
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
|
384 |
dirs.sort() |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
385 |
if '.hg' in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
386 |
yield root # found a repository |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
387 |
qroot = os.path.join(root, '.hg', 'patches') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
if recurse: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
391 |
# avoid recursing inside the .hg directory |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
392 |
dirs.remove('.hg') |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
393 |
else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
394 |
dirs[:] = [] # don't descend further |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
395 |
elif followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
396 |
newdirs = [] |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
397 |
for d in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
398 |
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
|
399 |
if adddir(seen_dirs, fname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
400 |
if os.path.islink(fname): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
401 |
for hgname in walkrepos(fname, True, seen_dirs): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
402 |
yield hgname |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
403 |
else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
404 |
newdirs.append(d) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
405 |
dirs[:] = newdirs |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
406 |
|
25739
3dabc9b7494a
changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Yuya Nishihara <yuya@tcha.org>
parents:
25660
diff
changeset
|
407 |
def intrev(rev): |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
408 |
"""Return integer for a given revision that can be used in comparison or |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
409 |
arithmetic operation""" |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
410 |
if rev is None: |
25739
3dabc9b7494a
changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Yuya Nishihara <yuya@tcha.org>
parents:
25660
diff
changeset
|
411 |
return wdirrev |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
412 |
return rev |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
413 |
|
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
414 |
def revsingle(repo, revspec, default='.'): |
19509
8963a706e075
revsingle: fix silly API issue (issue2992)
Matt Mackall <mpm@selenic.com>
parents:
19154
diff
changeset
|
415 |
if not revspec and revspec != 0: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
416 |
return repo[default] |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
417 |
|
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
418 |
l = revrange(repo, [revspec]) |
22814
8110405cf8ae
revset-limit: use boolean testing instead of `len(revs) < 1`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21799
diff
changeset
|
419 |
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
|
420 |
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
|
421 |
return repo[l.last()] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
422 |
|
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
423 |
def _pairspec(revspec): |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
424 |
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
|
425 |
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
|
426 |
|
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
427 |
def revpair(repo, revs): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
428 |
if not revs: |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
429 |
return repo.dirstate.p1(), None |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
430 |
|
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
431 |
l = revrange(repo, revs) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
432 |
|
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
433 |
if not l: |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
434 |
first = second = None |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
435 |
elif l.isascending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
436 |
first = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
437 |
second = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
438 |
elif l.isdescending(): |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
439 |
first = l.max() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
440 |
second = l.min() |
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
441 |
else: |
22816
20d998395ee7
revpair: use `first` and `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22815
diff
changeset
|
442 |
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
|
443 |
second = l.last() |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
444 |
|
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
|
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
451 |
# 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
|
452 |
if first == second and len(revs) == 1 and not _pairspec(revs[0]): |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
453 |
return repo.lookup(first), None |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
454 |
|
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
455 |
return repo.lookup(first), repo.lookup(second) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
456 |
|
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
457 |
def revrange(repo, specs): |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
458 |
"""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
|
459 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
460 |
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
|
461 |
config options, such as revset aliases. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
462 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
463 |
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
|
464 |
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
|
465 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
466 |
``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
|
467 |
revision numbers. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
468 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
473 |
Specifying a single revset is allowed. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
474 |
|
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
475 |
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
|
476 |
integer revisions. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
477 |
""" |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
478 |
allspecs = [] |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
479 |
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
|
480 |
if isinstance(spec, int): |
31024
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30639
diff
changeset
|
481 |
spec = revsetlang.formatspec('rev(%d)', spec) |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
482 |
allspecs.append(spec) |
31025
6cf2857526c7
scmutil: proxy revrange() through repo to break import cycles
Yuya Nishihara <yuya@tcha.org>
parents:
31024
diff
changeset
|
483 |
return repo.anyrevs(allspecs, user=True) |
14320 | 484 |
|
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
485 |
def meaningfulparents(repo, ctx): |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
486 |
"""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
|
487 |
|
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
is not the preceding revision. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
491 |
""" |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
492 |
parents = ctx.parents() |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
493 |
if len(parents) > 1: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
494 |
return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
495 |
if repo.ui.debugflag: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
496 |
return [parents[0], repo['null']] |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
497 |
if parents[0].rev() >= intrev(ctx.rev()) - 1: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
498 |
return [] |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
499 |
return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
500 |
|
14320 | 501 |
def expandpats(pats): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
502 |
'''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
|
503 |
On posix we assume it already has already been done by sh.''' |
14320 | 504 |
if not util.expandglobs: |
505 |
return list(pats) |
|
506 |
ret = [] |
|
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
507 |
for kindpat in pats: |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
508 |
kind, pat = matchmod._patsplit(kindpat, None) |
14320 | 509 |
if kind is None: |
510 |
try: |
|
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
511 |
globbed = glob.glob(pat) |
14320 | 512 |
except re.error: |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
513 |
globbed = [pat] |
14320 | 514 |
if globbed: |
515 |
ret.extend(globbed) |
|
516 |
continue |
|
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
517 |
ret.append(kindpat) |
14320 | 518 |
return ret |
519 |
||
26326
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
520 |
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
|
521 |
badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
522 |
'''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
|
523 |
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
|
524 |
is provided.''' |
14320 | 525 |
if pats == ("",): |
526 |
pats = [] |
|
26326
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
527 |
if opts is None: |
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
528 |
opts = {} |
14320 | 529 |
if not globbed and default == 'relpath': |
530 |
pats = expandpats(pats or []) |
|
14670
19197fa4c41c
scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents:
14669
diff
changeset
|
531 |
|
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
532 |
def bad(f, msg): |
24338
ca1365078c86
scmutil: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24175
diff
changeset
|
533 |
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
|
534 |
|
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
535 |
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
|
536 |
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
|
537 |
|
25466
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
538 |
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
|
539 |
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
|
540 |
|
24447
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
541 |
if m.always(): |
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
542 |
pats = [] |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
543 |
return m, pats |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
544 |
|
26328
188c1e9506f5
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26327
diff
changeset
|
545 |
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
|
546 |
badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
547 |
'''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
|
548 |
return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] |
14320 | 549 |
|
550 |
def matchall(repo): |
|
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
551 |
'''Return a matcher that will efficiently match everything.''' |
14320 | 552 |
return matchmod.always(repo.root, repo.getcwd()) |
553 |
||
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
554 |
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
|
555 |
'''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
|
556 |
return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn) |
14320 | 557 |
|
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
558 |
def origpath(ui, repo, filepath): |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
559 |
'''customize where .orig files are created |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
560 |
|
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
561 |
Fetch user defined path from config file: [ui] origbackuppath = <path> |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
562 |
Fall back to default (filepath) if not specified |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
563 |
''' |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
564 |
origbackuppath = ui.config('ui', 'origbackuppath', None) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
565 |
if origbackuppath is None: |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
566 |
return filepath + ".orig" |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
567 |
|
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
568 |
filepathfromroot = os.path.relpath(filepath, start=repo.root) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
569 |
fullorigpath = repo.wjoin(origbackuppath, filepathfromroot) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
570 |
|
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
571 |
origbackupdir = repo.vfs.dirname(fullorigpath) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
572 |
if not repo.vfs.exists(origbackupdir): |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
573 |
ui.note(_('creating directory: %s\n') % origbackupdir) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
574 |
util.makedirs(origbackupdir) |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
575 |
|
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
576 |
return fullorigpath + ".orig" |
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27610
diff
changeset
|
577 |
|
26329
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
578 |
def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None): |
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
579 |
if opts is None: |
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
580 |
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
|
581 |
m = matcher |
14320 | 582 |
if dry_run is None: |
583 |
dry_run = opts.get('dry_run') |
|
584 |
if similarity is None: |
|
585 |
similarity = float(opts.get('similarity') or 0) |
|
23533
891aaa7c0c70
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents:
23481
diff
changeset
|
586 |
|
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
587 |
ret = 0 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
588 |
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
|
589 |
|
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
590 |
wctx = repo[None] |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
591 |
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
|
592 |
submatch = matchmod.subdirmatcher(subpath, m) |
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29771
diff
changeset
|
593 |
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
|
594 |
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
|
595 |
try: |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
596 |
if sub.addremove(submatch, prefix, opts, dry_run, similarity): |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
597 |
ret = 1 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
598 |
except error.LookupError: |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
599 |
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
|
600 |
% join(subpath)) |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
601 |
|
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
602 |
rejected = [] |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
603 |
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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
|
25434
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
608 |
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
|
609 |
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
|
610 |
badmatch) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
611 |
|
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
612 |
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
|
613 |
toprint = unknownset.copy() |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
614 |
toprint.update(deleted) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
615 |
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
|
616 |
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
|
617 |
if abs in unknownset: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
618 |
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
|
619 |
else: |
23686
164915e8ef7b
narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents:
23582
diff
changeset
|
620 |
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
|
621 |
repo.ui.status(status) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
622 |
|
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
623 |
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
|
624 |
similarity) |
14320 | 625 |
|
626 |
if not dry_run: |
|
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
627 |
_markchanges(repo, unknown + forgotten, deleted, renames) |
14320 | 628 |
|
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
629 |
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
|
630 |
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
|
631 |
return 1 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
632 |
return ret |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
633 |
|
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
634 |
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
|
635 |
'''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
|
636 |
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
|
637 |
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
|
638 |
rejected = [] |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
639 |
|
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
640 |
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
|
641 |
|
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
642 |
if repo.ui.verbose: |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
643 |
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
|
644 |
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
|
645 |
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
|
646 |
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
|
647 |
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
|
648 |
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
|
649 |
else: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
650 |
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
|
651 |
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
|
652 |
|
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
653 |
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
|
654 |
similarity) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
655 |
|
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
656 |
_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
|
657 |
|
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
658 |
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
|
659 |
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
|
660 |
return 1 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
661 |
return 0 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
662 |
|
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
663 |
def _interestingfiles(repo, matcher): |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
664 |
'''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
|
665 |
about. |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
666 |
|
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
667 |
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
|
668 |
whether files are modified or clean.''' |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
669 |
added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
20006
diff
changeset
|
670 |
audit_path = pathutil.pathauditor(repo.root) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
671 |
|
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
672 |
ctx = repo[None] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
673 |
dirstate = repo.dirstate |
19655
1d07bf106c2a
addremove: don't do full walks
Siddharth Agarwal <sid0@fb.com>
parents:
19509
diff
changeset
|
674 |
walkresults = dirstate.walk(matcher, sorted(ctx.substate), True, False, |
1d07bf106c2a
addremove: don't do full walks
Siddharth Agarwal <sid0@fb.com>
parents:
19509
diff
changeset
|
675 |
full=False) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
676 |
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
|
677 |
dstate = dirstate[abs] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
678 |
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
|
679 |
unknown.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
680 |
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
|
681 |
deleted.append(abs) |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
682 |
elif dstate == 'r' and st: |
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
683 |
forgotten.append(abs) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
684 |
# for finding renames |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
685 |
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
|
686 |
removed.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
687 |
elif dstate == 'a': |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
688 |
added.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
689 |
|
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
690 |
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
|
691 |
|
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
692 |
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
|
693 |
'''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
|
694 |
renames = {} |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
695 |
if similarity > 0: |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
696 |
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
|
697 |
similarity): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
698 |
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
|
699 |
or not matcher.exact(new)): |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
700 |
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
|
701 |
'(%d%% similar)\n') % |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
702 |
(matcher.rel(old), matcher.rel(new), |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
703 |
score * 100)) |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
704 |
renames[new] = old |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
705 |
return renames |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
706 |
|
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
707 |
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
|
708 |
'''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
|
709 |
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
|
710 |
wctx = repo[None] |
27851
4133a306606c
with: use context manager in _markchanges
Bryan O'Sullivan <bryano@fb.com>
parents:
27706
diff
changeset
|
711 |
with repo.wlock(): |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
712 |
wctx.forget(deleted) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
713 |
wctx.add(unknown) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
714 |
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
|
715 |
wctx.copy(old, new) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
716 |
|
14320 | 717 |
def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
718 |
"""Update the dirstate to reflect the intent of copying src to dst. For |
|
719 |
different reasons it might not end with dst being marked as copied from src. |
|
720 |
""" |
|
721 |
origsrc = repo.dirstate.copied(src) or src |
|
722 |
if dst == origsrc: # copying back a copy? |
|
723 |
if repo.dirstate[dst] not in 'mn' and not dryrun: |
|
724 |
repo.dirstate.normallookup(dst) |
|
725 |
else: |
|
726 |
if repo.dirstate[origsrc] == 'a' and origsrc == src: |
|
727 |
if not ui.quiet: |
|
728 |
ui.warn(_("%s has not been committed yet, so no copy " |
|
729 |
"data will be stored for %s.\n") |
|
730 |
% (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd))) |
|
731 |
if repo.dirstate[dst] in '?r' and not dryrun: |
|
732 |
wctx.add([dst]) |
|
733 |
elif not dryrun: |
|
734 |
wctx.copy(origsrc, dst) |
|
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
735 |
|
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
736 |
def readrequires(opener, supported): |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
737 |
'''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
|
738 |
are in the list of supported features.''' |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
739 |
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
|
740 |
missings = [] |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
741 |
for r in requirements: |
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
742 |
if r not in supported: |
14484
4582a4dd1817
requires: note apparent corruption
Matt Mackall <mpm@selenic.com>
parents:
14483
diff
changeset
|
743 |
if not r or not r[0].isalnum(): |
4582a4dd1817
requires: note apparent corruption
Matt Mackall <mpm@selenic.com>
parents:
14483
diff
changeset
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
if missings: |
16683 | 748 |
raise error.RequirementError( |
20820
f8e531a3a77c
repo: rephrase the "missing requirement" error message
Mads Kiilerich <madski@unity3d.com>
parents:
20819
diff
changeset
|
749 |
_("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
|
750 |
% " ".join(missings), |
26421
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
26329
diff
changeset
|
751 |
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
|
752 |
" for more information")) |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
753 |
return requirements |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
754 |
|
24934
5abd0a76bc8f
requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents:
24755
diff
changeset
|
755 |
def writerequires(opener, requirements): |
27706
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
756 |
with opener('requires', 'w') as fp: |
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
757 |
for r in sorted(requirements): |
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
758 |
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
|
759 |
|
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
760 |
class filecachesubentry(object): |
20042
9a72d3886888
scmutil.filecacheentry: make stat argument to constructor mandatory
Siddharth Agarwal <sid0@fb.com>
parents:
20033
diff
changeset
|
761 |
def __init__(self, path, stat): |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
762 |
self.path = path |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
763 |
self.cachestat = None |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
764 |
self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
765 |
|
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
766 |
if stat: |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
767 |
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
|
768 |
|
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
769 |
if self.cachestat: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
770 |
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
|
771 |
else: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
772 |
# 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
|
773 |
self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
774 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
775 |
def refresh(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
776 |
if self.cacheable(): |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
777 |
self.cachestat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
778 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
779 |
def cacheable(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
780 |
if self._cacheable is not None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
781 |
return self._cacheable |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
782 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
783 |
# we don't know yet, assume it is for now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
784 |
return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
785 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
786 |
def changed(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
787 |
# no point in going further if we can't cache it |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
788 |
if not self.cacheable(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
789 |
return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
790 |
|
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
791 |
newstat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
792 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
793 |
# 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
|
794 |
if newstat and self._cacheable is None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
795 |
self._cacheable = newstat.cacheable() |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
796 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
797 |
# check again |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
798 |
if not self._cacheable: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
799 |
return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
800 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
801 |
if self.cachestat != newstat: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
802 |
self.cachestat = newstat |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
803 |
return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
804 |
else: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
805 |
return False |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
806 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
807 |
@staticmethod |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
808 |
def stat(path): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
809 |
try: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
810 |
return util.cachestat(path) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25658
diff
changeset
|
811 |
except OSError as e: |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
812 |
if e.errno != errno.ENOENT: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
813 |
raise |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
814 |
|
20044
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
815 |
class filecacheentry(object): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
816 |
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
|
817 |
self._entries = [] |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
818 |
for path in paths: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
819 |
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
|
820 |
|
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
821 |
def changed(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
822 |
'''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
|
823 |
for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
824 |
if entry.changed(): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
825 |
return True |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
826 |
return False |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
827 |
|
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
828 |
def refresh(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
829 |
for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
830 |
entry.refresh() |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
831 |
|
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
832 |
class filecache(object): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
833 |
'''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
|
834 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
835 |
Records stat info when called in _filecache. |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
836 |
|
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
837 |
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
|
838 |
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
|
839 |
_filecache. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
840 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
841 |
Mercurial either atomic renames or appends for files under .hg, |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
842 |
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
|
843 |
to tell us if a file has been replaced. If it can't, we fallback to |
26098 | 844 |
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
|
845 |
propertycache). |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
846 |
|
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
847 |
''' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
848 |
def __init__(self, *paths): |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
849 |
self.paths = paths |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
850 |
|
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
851 |
def join(self, obj, fname): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
852 |
"""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
|
853 |
|
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
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
|
857 |
""" |
31285
1937671105bc
filecache: make 'join' abstract
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31217
diff
changeset
|
858 |
raise NotImplementedError |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
859 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
860 |
def __call__(self, func): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
861 |
self.func = func |
31419
1fc3d1f02865
scmutil: make function name bytes in class filecache
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31349
diff
changeset
|
862 |
self.name = func.__name__.encode('ascii') |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
863 |
return self |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
864 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
865 |
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
|
866 |
# 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
|
867 |
if obj is None: |
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
868 |
return self |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
869 |
# do we need to check if the file changed? |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
870 |
if self.name in obj.__dict__: |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
871 |
assert self.name in obj._filecache, self.name |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
872 |
return obj.__dict__[self.name] |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
873 |
|
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
874 |
entry = obj._filecache.get(self.name) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
875 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
876 |
if entry: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
877 |
if entry.changed(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
878 |
entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
879 |
else: |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
880 |
paths = [self.join(obj, path) for path in self.paths] |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
881 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
882 |
# 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
|
883 |
# 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
|
884 |
entry = filecacheentry(paths, True) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
885 |
entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
886 |
|
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
887 |
obj._filecache[self.name] = entry |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
888 |
|
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
889 |
obj.__dict__[self.name] = entry.obj |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
890 |
return entry.obj |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
891 |
|
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
892 |
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
|
893 |
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
|
894 |
# 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
|
895 |
# implies X in _filecache |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
896 |
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
|
897 |
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
|
898 |
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
|
899 |
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
|
900 |
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
|
901 |
|
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
902 |
ce.obj = value # update cached copy |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
903 |
obj.__dict__[self.name] = value # update copy returned by obj.x |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
904 |
|
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
905 |
def __delete__(self, obj): |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
906 |
try: |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
907 |
del obj.__dict__[self.name] |
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
908 |
except KeyError: |
18177
203b7a759218
scmutil: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents:
17992
diff
changeset
|
909 |
raise AttributeError(self.name) |
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
|
910 |
|
f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents:
26433
diff
changeset
|
911 |
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
|
912 |
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
|
913 |
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
|
914 |
'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
|
915 |
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
|
916 |
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
|
917 |
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
|
918 |
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
|
919 |
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
|
920 |
|
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
|
921 |
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
|
922 |
"""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
|
923 |
|
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
|
924 |
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
|
925 |
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
|
926 |
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
|
927 |
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
|
928 |
**kwargs) |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
929 |
|
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
930 |
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
|
931 |
"""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
|
932 |
""" |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
933 |
# experimental config: format.generaldelta |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
934 |
return (ui.configbool('format', 'generaldelta', False) |
27093
41d3e307a7c1
format: create new repository as 'generaldelta' by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26907
diff
changeset
|
935 |
or ui.configbool('format', 'usegeneraldelta', True)) |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
936 |
|
26907
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
937 |
def gddeltaconfig(ui): |
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
938 |
"""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
|
939 |
""" |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
940 |
# experimental config: format.generaldelta |
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
941 |
return ui.configbool('format', 'generaldelta', False) |
31553
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
942 |
|
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
943 |
class simplekeyvaluefile(object): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
944 |
"""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
|
945 |
|
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
946 |
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
|
947 |
contain '\n' characters""" |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
948 |
|
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
949 |
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
|
950 |
self.vfs = vfs |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
951 |
self.path = path |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
952 |
|
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
953 |
def read(self): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
954 |
lines = self.vfs.readlines(self.path) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
955 |
try: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
956 |
d = dict(line[:-1].split('=', 1) for line in lines if line) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
957 |
except ValueError as e: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
958 |
raise error.CorruptedState(str(e)) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
959 |
return d |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
960 |
|
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
961 |
def write(self, data): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
962 |
"""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
|
963 |
data is a dict. Keys must be alphanumerical and start with a letter. |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
964 |
Values must not contain newline characters.""" |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
965 |
lines = [] |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
966 |
for k, v in data.items(): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
967 |
if not k[0].isalpha(): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
968 |
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
|
969 |
raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
970 |
if not k.isalnum(): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
971 |
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
|
972 |
raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
973 |
if '\n' in v: |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
974 |
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
|
975 |
raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31419
diff
changeset
|
976 |
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
|
977 |
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
|
978 |
fp.write(''.join(lines)) |