annotate hgext/narrow/narrowdirstate.py @ 49287:7fe82a5101c9

py3: use `zip()` instead of trying to use `itertools.izip()`
author Manuel Jacob <me@manueljacob.de>
date Sun, 29 May 2022 15:38:01 +0200
parents 6000f5b25c9b
children f4733654f144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
1 # narrowdirstate.py - extensions to mercurial dirstate to support narrow clones
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
2 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
3 # Copyright 2017 Google, Inc.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
4 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
7
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
8
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
9 from mercurial.i18n import _
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
10 from mercurial import error
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
11
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
12
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
13 def wrapdirstate(repo, dirstate):
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
14 """Add narrow spec dirstate ignore, block changes outside narrow spec."""
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
15
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
16 def _editfunc(fn):
42456
87a34c767384 merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 40087
diff changeset
17 def _wrapper(self, *args, **kwargs):
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
18 narrowmatch = repo.narrowmatch()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
19 for f in args:
39960
1a7d901a0a0c narrow: avoid looking up dirstate again when editing dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents: 38869
diff changeset
20 if f is not None and not narrowmatch(f) and f not in self:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
21 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
22 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
23 b"cannot track '%s' - it is outside "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
24 + b"the narrow clone"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
25 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
26 % f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
27 )
42456
87a34c767384 merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 40087
diff changeset
28 return fn(self, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42456
diff changeset
29
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
30 return _wrapper
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
31
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
32 class narrowdirstate(dirstate.__class__):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
33 # Prevent adding/editing/copying/deleting files that are outside the
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
34 # sparse checkout
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
35 @_editfunc
42456
87a34c767384 merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 40087
diff changeset
36 def normal(self, *args, **kwargs):
87a34c767384 merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 40087
diff changeset
37 return super(narrowdirstate, self).normal(*args, **kwargs)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
38
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
39 @_editfunc
48388
f5dea753fe4e win32text: drop associated dirstate cache information on revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47599
diff changeset
40 def set_tracked(self, *args, **kwargs):
f5dea753fe4e win32text: drop associated dirstate cache information on revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47599
diff changeset
41 return super(narrowdirstate, self).set_tracked(*args, **kwargs)
47593
f927ad5a4e2c dirstate: add a `set_tracked` method for "hg add"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
42
f927ad5a4e2c dirstate: add a `set_tracked` method for "hg add"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
43 @_editfunc
47599
cce51119bfe6 dirstate: add a `set_untracked` method for "hg remove"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47593
diff changeset
44 def set_untracked(self, *args):
cce51119bfe6 dirstate: add a `set_untracked` method for "hg remove"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47593
diff changeset
45 return super(narrowdirstate, self).set_untracked(*args)
cce51119bfe6 dirstate: add a `set_untracked` method for "hg remove"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47593
diff changeset
46
cce51119bfe6 dirstate: add a `set_untracked` method for "hg remove"-like usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47593
diff changeset
47 @_editfunc
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
48 def add(self, *args):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
49 return super(narrowdirstate, self).add(*args)
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
50
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
51 @_editfunc
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
52 def normallookup(self, *args):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
53 return super(narrowdirstate, self).normallookup(*args)
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
54
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
55 @_editfunc
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
56 def copy(self, *args):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
57 return super(narrowdirstate, self).copy(*args)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
58
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
59 @_editfunc
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
60 def remove(self, *args):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
61 return super(narrowdirstate, self).remove(*args)
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
62
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
63 @_editfunc
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
64 def merge(self, *args):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
65 return super(narrowdirstate, self).merge(*args)
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
66
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
67 def rebuild(self, parent, allfiles, changedfiles=None):
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
68 if changedfiles is None:
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
69 # Rebuilding entire dirstate, let's filter allfiles to match the
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
70 # narrowspec.
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
71 allfiles = [f for f in allfiles if repo.narrowmatch()(f)]
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
72 super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
73
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
74 dirstate.__class__ = narrowdirstate
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 36200
diff changeset
75 return dirstate