Mercurial > hg
annotate hgext/narrow/narrowrepo.py @ 38835:a232e6744ba3
narrow: move requirement constant from changegroup to repository
As suggested by Gregory Szorc.
Differential Revision: https://phab.mercurial-scm.org/D4094
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 03 Aug 2018 11:02:34 -0700 |
parents | e411774a2e0f |
children | 576eef1ab43d |
rev | line source |
---|---|
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 # narrowrepo.py - repository which supports narrow revlogs, lazy loading |
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 import ( |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36155
diff
changeset
|
11 hg, |
36160
9fd8c2a3db5a
narrowspec: move module into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36159
diff
changeset
|
12 narrowspec, |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38818
diff
changeset
|
13 repository, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 ) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 from . import ( |
38128
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
37380
diff
changeset
|
17 narrowdirstate, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 narrowrevlog, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 ) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 def wrappostshare(orig, sourcerepo, destrepo, **kwargs): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 orig(sourcerepo, destrepo, **kwargs) |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38818
diff
changeset
|
23 if repository.NARROW_REQUIREMENT in sourcerepo.requirements: |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 with destrepo.wlock(): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 with destrepo.vfs('shared', 'a') as fp: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 fp.write(narrowspec.FILENAME + '\n') |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 def unsharenarrowspec(orig, ui, repo, repopath): |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38818
diff
changeset
|
29 if (repository.NARROW_REQUIREMENT in repo.requirements |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 and repo.path == repopath and repo.shared()): |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36155
diff
changeset
|
31 srcrepo = hg.sharedreposource(repo) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 with srcrepo.vfs(narrowspec.FILENAME) as f: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 spec = f.read() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 with repo.vfs(narrowspec.FILENAME, 'w') as f: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 f.write(spec) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 return orig(ui, repo, repopath) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
36466
a8b4d7673d8e
narrow: move checking for narrow requirement into _narrowmatch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36464
diff
changeset
|
38 def wraprepo(repo): |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 """Enables narrow clone functionality on a single local repository.""" |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 class narrowrepository(repo.__class__): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 def file(self, f): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 fl = super(narrowrepository, self).file(f) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 narrowrevlog.makenarrowfilelog(fl, self.narrowmatch()) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 return fl |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
38128
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
37380
diff
changeset
|
48 def _makedirstate(self): |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
37380
diff
changeset
|
49 dirstate = super(narrowrepository, self)._makedirstate() |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
37380
diff
changeset
|
50 return narrowdirstate.wrapdirstate(self, dirstate) |
1cba497491be
narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents:
37380
diff
changeset
|
51 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 repo.__class__ = narrowrepository |