annotate mercurial/unionrepo.py @ 39778:a6b3c4c1019f

revlog: move censor logic out of censor extension The censor extension is doing very low-level things with revlogs. It is fundamentally impossible for this logic to remain in the censor extension while support multiple storage backends: we need each storage backend to implement censor in its own storage-specific way. This commit effectively moves the revlog-specific censoring code to be a method of revlogs themselves. We've defined a new API on the file storage interface for censoring an individual node. Even though the current censoring code doesn't use it, the API requires a transaction instance because it logically makes sense for storage backends to require an active transaction (which implies a held write lock) in order to rewrite storage. After this commit, the censor extension has been reduced to boilerplate precondition checking before invoking the generic storage API. I tried to keep the code as similar as possible. But some minor changes were made: * We use self._io instead of instantiating a new revlogio instance. * We compare self.version against REVLOGV0 instead of != REVLOGV1 because presumably all future revlog versions will support censoring. * We use self.opener instead of going through repo.svfs (we don't have a handle on the repo instance from a revlog). * "revlog" dropped * Replace "flog" with "self". Differential Revision: https://phab.mercurial-scm.org/D4656
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 18 Sep 2018 17:51:43 -0700
parents 5ccd791344f3
children 24e493ec2229
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
1 # unionrepo.py - repository class for viewing union of repository changesets
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
2 #
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
3 # Derived from bundlerepo.py
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
4 # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com>
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
5 # Copyright 2013 Unity Technologies, Mads Kiilerich <madski@unity3d.com>
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
6 #
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
8 # GNU General Public License version 2 or any later version.
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
9
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
10 """Repository class for "in-memory pull" of one local repository to another,
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
11 allowing operations like diff and log with revsets.
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
12 """
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
13
25988
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
14 from __future__ import absolute_import
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
15
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
16 from .i18n import _
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
17 from .node import nullid
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
18
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
19 from . import (
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
20 changelog,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
21 cmdutil,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26230
diff changeset
22 error,
25988
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
23 filelog,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
24 localrepo,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
25 manifest,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
26 mdiff,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
27 pathutil,
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30374
diff changeset
28 pycompat,
25988
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
29 revlog,
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
30 util,
31242
854f9188e354 vfs: use 'vfs' module directly in 'mercurial.unionrepo'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30743
diff changeset
31 vfs as vfsmod,
25988
83f220c7d6f0 unionrepo: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24835
diff changeset
32 )
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
33
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
34 class unionrevlog(revlog.revlog):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
35 def __init__(self, opener, indexfile, revlog2, linkmapper):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
36 # How it works:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
37 # To retrieve a revision, we just need to know the node id so we can
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
38 # look it up in revlog2.
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
39 #
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
40 # To differentiate a rev in the second revlog from a rev in the revlog,
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
41 # we check revision against repotiprev.
31242
854f9188e354 vfs: use 'vfs' module directly in 'mercurial.unionrepo'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30743
diff changeset
42 opener = vfsmod.readonlyvfs(opener)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
43 revlog.revlog.__init__(self, opener, indexfile)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
44 self.revlog2 = revlog2
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
45
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
46 n = len(self)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
47 self.repotiprev = n - 1
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
48 self.bundlerevs = set() # used by 'bundle()' revset expression
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
49 for rev2 in self.revlog2:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
50 rev = self.revlog2.index[rev2]
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
51 # rev numbers - in revlog2, very different from self.rev
38176
df5f6881cebd unionrepo: fill in uncompressed length of revlog entry
Yuya Nishihara <yuya@tcha.org>
parents: 37717
diff changeset
52 _start, _csize, rsize, base, linkrev, p1rev, p2rev, node = rev
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 26587
diff changeset
53 flags = _start & 0xFFFF
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
54
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
55 if linkmapper is None: # link is to same revlog
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
56 assert linkrev == rev2 # we never link back
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
57 link = n
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
58 else: # rev must be mapped from repo2 cl to unified cl by linkmapper
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
59 link = linkmapper(linkrev)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
60
26230
6b16a3538c20 unionrepo: take delta base in account with building unified revlog
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25988
diff changeset
61 if linkmapper is not None: # link is to same revlog
6b16a3538c20 unionrepo: take delta base in account with building unified revlog
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25988
diff changeset
62 base = linkmapper(base)
6b16a3538c20 unionrepo: take delta base in account with building unified revlog
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25988
diff changeset
63
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
64 if node in self.nodemap:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
65 # this happens for the common revlog revisions
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
66 self.bundlerevs.add(self.nodemap[node])
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
67 continue
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
68
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
69 p1node = self.revlog2.node(p1rev)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
70 p2node = self.revlog2.node(p2rev)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
71
38176
df5f6881cebd unionrepo: fill in uncompressed length of revlog entry
Yuya Nishihara <yuya@tcha.org>
parents: 37717
diff changeset
72 # TODO: it's probably wrong to set compressed length to None, but
df5f6881cebd unionrepo: fill in uncompressed length of revlog entry
Yuya Nishihara <yuya@tcha.org>
parents: 37717
diff changeset
73 # I have no idea if csize is valid in the base revlog context.
df5f6881cebd unionrepo: fill in uncompressed length of revlog entry
Yuya Nishihara <yuya@tcha.org>
parents: 37717
diff changeset
74 e = (flags, None, rsize, base,
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
75 link, self.rev(p1node), self.rev(p2node), node)
38850
6104b203bec8 index: replace insert(-1, e) method by append(e) method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38176
diff changeset
76 self.index.append(e)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
77 self.nodemap[node] = n
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
78 self.bundlerevs.add(n)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
79 n += 1
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
80
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
81 def _chunk(self, rev):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
82 if rev <= self.repotiprev:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
83 return revlog.revlog._chunk(self, rev)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
84 return self.revlog2._chunk(self.node(rev))
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
85
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
86 def revdiff(self, rev1, rev2):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
87 """return or calculate a delta between two revisions"""
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
88 if rev1 > self.repotiprev and rev2 > self.repotiprev:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
89 return self.revlog2.revdiff(
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
90 self.revlog2.rev(self.node(rev1)),
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
91 self.revlog2.rev(self.node(rev2)))
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
92 elif rev1 <= self.repotiprev and rev2 <= self.repotiprev:
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
93 return self.baserevdiff(rev1, rev2)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
94
31724
f1e0446e804c unionrepo: avoid unnecessary node -> rev conversion
Jun Wu <quark@fb.com>
parents: 31242
diff changeset
95 return mdiff.textdiff(self.revision(rev1), self.revision(rev2))
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
96
37497
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
97 def revision(self, nodeorrev, _df=None, raw=False):
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
98 """return an uncompressed revision of a given node or revision
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
99 number.
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
100 """
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
101 if isinstance(nodeorrev, int):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
102 rev = nodeorrev
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
103 node = self.node(rev)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
104 else:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
105 node = nodeorrev
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
106 rev = self.rev(node)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
107
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
108 if node == nullid:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
109 return ""
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
110
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
111 if rev > self.repotiprev:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
112 text = self.revlog2.revision(node)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
113 self._cache = (node, rev, text)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
114 else:
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
115 text = self.baserevision(rev)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
116 # already cached
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
117 return text
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
118
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
119 def baserevision(self, nodeorrev):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
120 # Revlog subclasses may override 'revision' method to modify format of
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
121 # content retrieved from revlog. To use unionrevlog with such class one
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
122 # needs to override 'baserevision' and make more specific call here.
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
123 return revlog.revlog.revision(self, nodeorrev)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
124
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
125 def baserevdiff(self, rev1, rev2):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
126 # Exists for the same purpose as baserevision.
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
127 return revlog.revlog.revdiff(self, rev1, rev2)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
128
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
129 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
130 raise NotImplementedError
34219
21fc747e1bc5 revlog: update signature of dummy addgroup() in bundlerepo and unionrepo
Yuya Nishihara <yuya@tcha.org>
parents: 33182
diff changeset
131 def addgroup(self, deltas, transaction, addrevisioncb=None):
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
132 raise NotImplementedError
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
133 def strip(self, rev, minlink):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
134 raise NotImplementedError
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
135 def checksize(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
136 raise NotImplementedError
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
137
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
138 class unionchangelog(unionrevlog, changelog.changelog):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
139 def __init__(self, opener, opener2):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
140 changelog.changelog.__init__(self, opener)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
141 linkmapper = None
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
142 changelog2 = changelog.changelog(opener2)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
143 unionrevlog.__init__(self, opener, self.indexfile, changelog2,
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
144 linkmapper)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
145
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
146 def baserevision(self, nodeorrev):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
147 # Although changelog doesn't override 'revision' method, some extensions
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
148 # may replace this class with another that does. Same story with
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
149 # manifest and filelog classes.
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
150 return changelog.changelog.revision(self, nodeorrev)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
151
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
152 def baserevdiff(self, rev1, rev2):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
153 return changelog.changelog.revdiff(self, rev1, rev2)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
154
30374
f2d146d1e8d6 manifest: add unionmanifestlog support
Durham Goode <durham@fb.com>
parents: 30218
diff changeset
155 class unionmanifest(unionrevlog, manifest.manifestrevlog):
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
156 def __init__(self, opener, opener2, linkmapper):
30374
f2d146d1e8d6 manifest: add unionmanifestlog support
Durham Goode <durham@fb.com>
parents: 30218
diff changeset
157 manifest.manifestrevlog.__init__(self, opener)
f2d146d1e8d6 manifest: add unionmanifestlog support
Durham Goode <durham@fb.com>
parents: 30218
diff changeset
158 manifest2 = manifest.manifestrevlog(opener2)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
159 unionrevlog.__init__(self, opener, self.indexfile, manifest2,
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
160 linkmapper)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
161
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
162 def baserevision(self, nodeorrev):
30374
f2d146d1e8d6 manifest: add unionmanifestlog support
Durham Goode <durham@fb.com>
parents: 30218
diff changeset
163 return manifest.manifestrevlog.revision(self, nodeorrev)
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
164
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
165 def baserevdiff(self, rev1, rev2):
30374
f2d146d1e8d6 manifest: add unionmanifestlog support
Durham Goode <durham@fb.com>
parents: 30218
diff changeset
166 return manifest.manifestrevlog.revdiff(self, rev1, rev2)
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
167
37497
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
168 class unionfilelog(filelog.filelog):
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
169 def __init__(self, opener, path, opener2, linkmapper, repo):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
170 filelog.filelog.__init__(self, opener, path)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
171 filelog2 = filelog.filelog(opener2, path)
37497
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
172 self._revlog = unionrevlog(opener, self.indexfile,
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
173 filelog2._revlog, linkmapper)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
174 self._repo = repo
37497
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
175 self.repotiprev = self._revlog.repotiprev
1541e1a8e87d filelog: wrap revlog instead of inheriting it (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34219
diff changeset
176 self.revlog2 = self._revlog.revlog2
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
177
19630
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
178 def baserevision(self, nodeorrev):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
179 return filelog.filelog.revision(self, nodeorrev)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
180
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
181 def baserevdiff(self, rev1, rev2):
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
182 return filelog.filelog.revdiff(self, rev1, rev2)
bb67f630b335 unionrevlog: extract 'baserevision' and 'baserevdiff' methods
Wojciech Lopata <lopek@fb.com>
parents: 18944
diff changeset
183
24118
76f6ae06ddf5 revlog: add "iscensored()" to revlog public API
Mike Edgar <adgar@google.com>
parents: 24003
diff changeset
184 def iscensored(self, rev):
76f6ae06ddf5 revlog: add "iscensored()" to revlog public API
Mike Edgar <adgar@google.com>
parents: 24003
diff changeset
185 """Check if a revision is censored."""
76f6ae06ddf5 revlog: add "iscensored()" to revlog public API
Mike Edgar <adgar@google.com>
parents: 24003
diff changeset
186 if rev <= self.repotiprev:
76f6ae06ddf5 revlog: add "iscensored()" to revlog public API
Mike Edgar <adgar@google.com>
parents: 24003
diff changeset
187 return filelog.filelog.iscensored(self, rev)
27723
bf86e3e87123 unionrepo: fix wrong rev being checked in iscensored (issue5024)
Sean Farley <sean@farley.io>
parents: 26587
diff changeset
188 node = self.node(rev)
bf86e3e87123 unionrepo: fix wrong rev being checked in iscensored (issue5024)
Sean Farley <sean@farley.io>
parents: 26587
diff changeset
189 return self.revlog2.iscensored(self.revlog2.rev(node))
24118
76f6ae06ddf5 revlog: add "iscensored()" to revlog public API
Mike Edgar <adgar@google.com>
parents: 24003
diff changeset
190
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
191 class unionpeer(localrepo.localpeer):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
192 def canpush(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
193 return False
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
194
39605
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
195 class unionrepository(object):
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
196 """Represents the union of data in 2 repositories.
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
197
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
198 Instances are not usable if constructed directly. Use ``instance()``
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
199 or ``makeunionrepository()`` to create a usable instance.
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
200 """
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
201 def __init__(self, repo2, url):
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
202 self.repo2 = repo2
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
203 self._url = url
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
204
20790
49f2d5644f04 config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents: 19630
diff changeset
205 self.ui.setconfig('phases', 'publish', False, 'unionrepo')
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
206
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
207 @localrepo.unfilteredpropertycache
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
208 def changelog(self):
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20790
diff changeset
209 return unionchangelog(self.svfs, self.repo2.svfs)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
210
39763
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
211 @localrepo.unfilteredpropertycache
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
212 def manifestlog(self):
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
213 rootstore = unionmanifest(self.svfs, self.repo2.svfs,
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
214 self.unfiltered()._clrev)
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
215 return manifest.manifestlog(self.svfs, self, rootstore)
5ccd791344f3 localrepo: pass root manifest into manifestlog.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39605
diff changeset
216
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
217 def _clrev(self, rev2):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
218 """map from repo2 changelog rev to temporary rev in self.changelog"""
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
219 node = self.repo2.changelog.node(rev2)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
220 return self.changelog.rev(node)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
221
30218
1767723f71cf manifest: move manifest creation to a helper function
Durham Goode <durham@fb.com>
parents: 28222
diff changeset
222 def _constructmanifest(self):
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20790
diff changeset
223 return unionmanifest(self.svfs, self.repo2.svfs,
28222
b966e35aad78 unionrepo: properly handle hidden linkrev in revlog (issue5070)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27750
diff changeset
224 self.unfiltered()._clrev)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
225
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
226 def url(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
227 return self._url
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
228
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
229 def file(self, f):
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20790
diff changeset
230 return unionfilelog(self.svfs, f, self.repo2.svfs,
28222
b966e35aad78 unionrepo: properly handle hidden linkrev in revlog (issue5070)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27750
diff changeset
231 self.unfiltered()._clrev, self)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
232
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
233 def close(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
234 self.repo2.close()
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
235
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
236 def cancopy(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
237 return False
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
238
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
239 def peer(self):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
240 return unionpeer(self)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
241
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
242 def getcwd(self):
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30374
diff changeset
243 return pycompat.getcwd() # always outside the repo
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
244
39549
089fc0db0954 hg: allow extra arguments to be passed to repo creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38850
diff changeset
245 def instance(ui, path, create, intents=None, createopts=None):
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
246 if create:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26230
diff changeset
247 raise error.Abort(_('cannot create new union repository'))
33182
634997248c97 configitems: register the 'bundle.mainreporoot' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 31724
diff changeset
248 parentpath = ui.config("bundle", "mainreporoot")
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
249 if not parentpath:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
250 # try to find the correct path to the working directory repo
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30374
diff changeset
251 parentpath = cmdutil.findrepo(pycompat.getcwd())
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
252 if parentpath is None:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
253 parentpath = ''
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
254 if parentpath:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
255 # Try to make the full path relative so we get a nice, short URL.
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
256 # In particular, we don't want temp dir names in test outputs.
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30374
diff changeset
257 cwd = pycompat.getcwd()
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
258 if parentpath == cwd:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
259 parentpath = ''
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
260 else:
24835
e4f75c93f073 unionrepo: use pathutil.normasprefix to ensure os.sep at the end of cwd
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24118
diff changeset
261 cwd = pathutil.normasprefix(cwd)
18944
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
262 if parentpath.startswith(cwd):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
263 parentpath = parentpath[len(cwd):]
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
264 if path.startswith('union:'):
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
265 s = path.split(":", 1)[1].split("+", 1)
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
266 if len(s) == 1:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
267 repopath, repopath2 = parentpath, s[0]
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
268 else:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
269 repopath, repopath2 = s
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
270 else:
a9c443b3b240 unionrepo: read-only operations on a union of two localrepos
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
271 repopath, repopath2 = parentpath, path
39605
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
272
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
273 return makeunionrepository(ui, repopath, repopath2)
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
274
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
275 def makeunionrepository(ui, repopath1, repopath2):
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
276 """Make a union repository object from 2 local repo paths."""
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
277 repo1 = localrepo.instance(ui, repopath1, create=False)
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
278 repo2 = localrepo.instance(ui, repopath2, create=False)
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
279
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
280 url = 'union:%s+%s' % (util.expandpath(repopath1),
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
281 util.expandpath(repopath2))
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
282
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
283 class derivedunionrepository(unionrepository, repo1.__class__):
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
284 pass
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
285
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
286 repo = repo1
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
287 repo.__class__ = derivedunionrepository
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
288 unionrepository.__init__(repo1, repo2, url)
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
289
23f2299e9e53 unionrepo: dynamically create repository type from base repository
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
290 return repo