author | Augie Fackler <augie@google.com> |
Sun, 06 Oct 2019 09:45:02 -0400 | |
changeset 43076 | 2372284d9457 |
parent 42472 | 87a34c767384 |
child 43077 | 687b865b95ad |
permissions | -rw-r--r-- |
36117
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 |
from __future__ import absolute_import |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
|
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
from mercurial.i18n import _ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
11 |
from mercurial import error |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
12 |
|
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
14 |
def wrapdirstate(repo, dirstate): |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
"""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
|
16 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
17 |
def _editfunc(fn): |
42472
87a34c767384
merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
40088
diff
changeset
|
18 |
def _wrapper(self, *args, **kwargs): |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
narrowmatch = repo.narrowmatch() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
for f in args: |
39961
1a7d901a0a0c
narrow: avoid looking up dirstate again when editing dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
38908
diff
changeset
|
21 |
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:
42472
diff
changeset
|
22 |
raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
23 |
_( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
24 |
"cannot track '%s' - it is outside " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
25 |
+ "the narrow clone" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
26 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
27 |
% f |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
28 |
) |
42472
87a34c767384
merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
40088
diff
changeset
|
29 |
return fn(self, *args, **kwargs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42472
diff
changeset
|
30 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
31 |
return _wrapper |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
33 |
class narrowdirstate(dirstate.__class__): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
34 |
# 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:
36238
diff
changeset
|
35 |
# sparse checkout |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
36 |
@_editfunc |
42472
87a34c767384
merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
40088
diff
changeset
|
37 |
def normal(self, *args, **kwargs): |
87a34c767384
merge: fix race that could cause wrong size in dirstate
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
40088
diff
changeset
|
38 |
return super(narrowdirstate, self).normal(*args, **kwargs) |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
40 |
@_editfunc |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
41 |
def add(self, *args): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
42 |
return super(narrowdirstate, self).add(*args) |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
43 |
|
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
44 |
@_editfunc |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
45 |
def normallookup(self, *args): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
46 |
return super(narrowdirstate, self).normallookup(*args) |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
47 |
|
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
48 |
@_editfunc |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
49 |
def copy(self, *args): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
50 |
return super(narrowdirstate, self).copy(*args) |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
52 |
@_editfunc |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
53 |
def remove(self, *args): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
54 |
return super(narrowdirstate, self).remove(*args) |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
55 |
|
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
56 |
@_editfunc |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
57 |
def merge(self, *args): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
58 |
return super(narrowdirstate, self).merge(*args) |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
59 |
|
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
60 |
def rebuild(self, parent, allfiles, changedfiles=None): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
61 |
if changedfiles is None: |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
62 |
# 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:
36238
diff
changeset
|
63 |
# narrowspec. |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
64 |
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:
36238
diff
changeset
|
65 |
super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles) |
36117
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
|
38161
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
67 |
dirstate.__class__ = narrowdirstate |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
36238
diff
changeset
|
68 |
return dirstate |