annotate mercurial/bundlerepo.py @ 14161:8a0fca925992

bundlerepo: fix and improve getremotechanges Fixes the regression where incoming could show local changes introduced by rev 72c84f24b420.
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Mon, 02 May 2011 12:36:23 +0200
parents d8ba6fb2ce15
children 8aab5a82685f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
1 # bundlerepo.py - repository class for viewing uncompressed bundles
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
2 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
3 # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com>
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
4 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9676
diff changeset
6 # GNU General Public License version 2 or any later version.
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
7
8227
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
8 """Repository class for viewing uncompressed bundles.
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
9
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
10 This provides a read-only repository interface to bundles as if they
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
11 were part of the actual repository.
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
12 """
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
13
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7853
diff changeset
14 from node import nullid
3891
6b4127c7d52a Simplify i18n imports
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
15 from i18n import _
14158
d8ba6fb2ce15 bundlerepo: drop struct
Matt Mackall <mpm@selenic.com>
parents: 14144
diff changeset
16 import os, tempfile, shutil
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
17 import changegroup, util, mdiff, discovery
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
18 import localrepo, changelog, manifest, filelog, revlog, error
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
19
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
20 class bundlerevlog(revlog.revlog):
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
21 def __init__(self, opener, indexfile, bundle, linkmapper):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
22 # How it works:
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
23 # to retrieve a revision, we need to know the offset of
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
24 # the revision in the bundle (an unbundle object).
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
25 #
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
26 # We store this offset in the index (start), to differentiate a
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
27 # rev in the bundle and from a rev in the revlog, we check
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
28 # len(index[r]). If the tuple is bigger than 7, it is a bundle
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
29 # (it is bigger since we store the node to which the delta is)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
30 #
4257
1b5c38e9d7aa revlog: don't pass datafile as an argument
Matt Mackall <mpm@selenic.com>
parents: 4029
diff changeset
31 revlog.revlog.__init__(self, opener, indexfile)
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
32 self.bundle = bundle
2074
01ee43dda681 Fix bundle repos to use an index tuple consistent with revlogng
mason@suse.com
parents: 1981
diff changeset
33 self.basemap = {}
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6647
diff changeset
34 n = len(self)
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
35 chain = None
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
36 while 1:
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
37 chunkdata = bundle.deltachunk(chain)
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
38 if not chunkdata:
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
39 break
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
40 node = chunkdata['node']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
41 p1 = chunkdata['p1']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
42 p2 = chunkdata['p2']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
43 cs = chunkdata['cs']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
44 deltabase = chunkdata['deltabase']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
45 delta = chunkdata['delta']
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
46
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
47 size = len(delta)
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
48 start = bundle.tell() - size
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
49
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
50 link = linkmapper(cs)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
51 if node in self.nodemap:
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
52 # this can happen if two branches make the same change
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
53 chain = node
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
54 continue
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
55
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
56 for p in (p1, p2):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
57 if not p in self.nodemap:
9650
1ad02c04356c bundlerepo: fix small bug in exception raising
Sune Foldager <cryo@cyanite.org>
parents: 9198
diff changeset
58 raise error.LookupError(p, self.indexfile,
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7435
diff changeset
59 _("unknown parent"))
5167
aba624d2301d fix bundlerepo broken by 4205f626dc05
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4989
diff changeset
60 # start, size, full unc. size, base (unused), link, p1, p2, node
aba624d2301d fix bundlerepo broken by 4205f626dc05
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 4989
diff changeset
61 e = (revlog.offset_type(start, 0), size, -1, -1, link,
4979
06abdaf78788 revlog: add a magic null revision to our index
Matt Mackall <mpm@selenic.com>
parents: 4918
diff changeset
62 self.rev(p1), self.rev(p2), node)
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
63 self.basemap[n] = deltabase
4979
06abdaf78788 revlog: add a magic null revision to our index
Matt Mackall <mpm@selenic.com>
parents: 4918
diff changeset
64 self.index.insert(-1, e)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
65 self.nodemap[node] = n
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
66 chain = node
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
67 n += 1
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
68
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
69 def inbundle(self, rev):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
70 """is rev from the bundle"""
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
71 if rev < 0:
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
72 return False
2074
01ee43dda681 Fix bundle repos to use an index tuple consistent with revlogng
mason@suse.com
parents: 1981
diff changeset
73 return rev in self.basemap
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
74 def bundlebase(self, rev):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
75 return self.basemap[rev]
9676
48bf28d3c8dd bundlerepo: keep the bundlerevlog interface in sync with revlog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 9650
diff changeset
76 def _chunk(self, rev):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
77 # Warning: in case of bundle, the diff is against bundlebase,
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
78 # not against rev - 1
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
79 # XXX: could use some caching
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
80 if not self.inbundle(rev):
9676
48bf28d3c8dd bundlerepo: keep the bundlerevlog interface in sync with revlog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 9650
diff changeset
81 return revlog.revlog._chunk(self, rev)
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
82 self.bundle.seek(self.start(rev))
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
83 return self.bundle.read(self.length(rev))
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
84
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
85 def revdiff(self, rev1, rev2):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
86 """return or calculate a delta between two revisions"""
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
87 if self.inbundle(rev1) and self.inbundle(rev2):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
88 # hot path for bundle
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
89 revb = self.rev(self.bundlebase(rev2))
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
90 if revb == rev1:
9676
48bf28d3c8dd bundlerepo: keep the bundlerevlog interface in sync with revlog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 9650
diff changeset
91 return self._chunk(rev2)
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
92 elif not self.inbundle(rev1) and not self.inbundle(rev2):
4028
540d1059c802 bundlerepo: it was meant to be revdiff() instead of chunk()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3791
diff changeset
93 return revlog.revlog.revdiff(self, rev1, rev2)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
94
4989
1aaed3d69772 revlog: eliminate diff and patches functions
Matt Mackall <mpm@selenic.com>
parents: 4988
diff changeset
95 return mdiff.textdiff(self.revision(self.node(rev1)),
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
96 self.revision(self.node(rev2)))
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
97
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
98 def revision(self, node):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
99 """return an uncompressed revision of a given"""
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
100 if node == nullid:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
101 return ""
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
102
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
103 text = None
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
104 chain = []
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
105 iter_node = node
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
106 rev = self.rev(iter_node)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
107 # reconstruct the revision if it is from a changegroup
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
108 while self.inbundle(rev):
4984
b4066fcbd6ba revlog: mark cache private
Matt Mackall <mpm@selenic.com>
parents: 4979
diff changeset
109 if self._cache and self._cache[0] == iter_node:
b4066fcbd6ba revlog: mark cache private
Matt Mackall <mpm@selenic.com>
parents: 4979
diff changeset
110 text = self._cache[2]
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
111 break
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
112 chain.append(rev)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
113 iter_node = self.bundlebase(rev)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
114 rev = self.rev(iter_node)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
115 if text is None:
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
116 text = revlog.revlog.revision(self, iter_node)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
117
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
118 while chain:
9676
48bf28d3c8dd bundlerepo: keep the bundlerevlog interface in sync with revlog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 9650
diff changeset
119 delta = self._chunk(chain.pop())
4989
1aaed3d69772 revlog: eliminate diff and patches functions
Matt Mackall <mpm@selenic.com>
parents: 4988
diff changeset
120 text = mdiff.patches(text, [delta])
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
121
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
122 p1, p2 = self.parents(node)
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
123 if node != revlog.hash(text, p1, p2):
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7435
diff changeset
124 raise error.RevlogError(_("integrity check failed on %s:%d")
2257
8dafccbcede9 indent: fix alignment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2256
diff changeset
125 % (self.datafile, self.rev(node)))
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
126
4984
b4066fcbd6ba revlog: mark cache private
Matt Mackall <mpm@selenic.com>
parents: 4979
diff changeset
127 self._cache = (node, self.rev(node), text)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
128 return text
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
129
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
130 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
131 raise NotImplementedError
6647
602f7c1ab954 drop superfluous param from revlog.addgroup()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6569
diff changeset
132 def addgroup(self, revs, linkmapper, transaction):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
133 raise NotImplementedError
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
134 def strip(self, rev, minlink):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
135 raise NotImplementedError
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
136 def checksize(self):
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
137 raise NotImplementedError
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
138
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
139 class bundlechangelog(bundlerevlog, changelog.changelog):
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
140 def __init__(self, opener, bundle):
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
141 changelog.changelog.__init__(self, opener)
14142
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
142 linkmapper = lambda x: x
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
143 bundlerevlog.__init__(self, opener, self.indexfile, bundle,
cb91ea6af733 bundlerepo: port to new bundle API
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14076
diff changeset
144 linkmapper)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
145
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
146 class bundlemanifest(bundlerevlog, manifest.manifest):
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
147 def __init__(self, opener, bundle, linkmapper):
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
148 manifest.manifest.__init__(self, opener)
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
149 bundlerevlog.__init__(self, opener, self.indexfile, bundle,
4257
1b5c38e9d7aa revlog: don't pass datafile as an argument
Matt Mackall <mpm@selenic.com>
parents: 4029
diff changeset
150 linkmapper)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
151
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
152 class bundlefilelog(bundlerevlog, filelog.filelog):
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
153 def __init__(self, opener, path, bundle, linkmapper):
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
154 filelog.filelog.__init__(self, opener, path)
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
155 bundlerevlog.__init__(self, opener, self.indexfile, bundle,
4257
1b5c38e9d7aa revlog: don't pass datafile as an argument
Matt Mackall <mpm@selenic.com>
parents: 4029
diff changeset
156 linkmapper)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
157
1946
9fee186f7f0d bundlerepo: remove relative import, fix a comment
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1942
diff changeset
158 class bundlerepository(localrepo.localrepository):
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
159 def __init__(self, ui, path, bundlename):
6314
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
160 self._tempparent = None
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
161 try:
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
162 localrepo.localrepository.__init__(self, ui, path)
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
163 except error.RepoError:
6314
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
164 self._tempparent = tempfile.mkdtemp()
9198
061eeb602354 coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents: 8312
diff changeset
165 localrepo.instance(ui, self._tempparent, 1)
6314
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
166 localrepo.localrepository.__init__(self, ui, self._tempparent)
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2273
diff changeset
167
6129
3d666e8e6398 bundlerepo: fix inconsistency of parsed and internal name (issue #821)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5664
diff changeset
168 if path:
11154
17031fea4e95 expand paths to local repository or bundle in appropriate classes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 10282
diff changeset
169 self._url = 'bundle:' + util.expandpath(path) + '+' + bundlename
6129
3d666e8e6398 bundlerepo: fix inconsistency of parsed and internal name (issue #821)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5664
diff changeset
170 else:
3d666e8e6398 bundlerepo: fix inconsistency of parsed and internal name (issue #821)
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5664
diff changeset
171 self._url = 'bundle:' + bundlename
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2273
diff changeset
172
2273
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
173 self.tempfile = None
13274
57d433f632b7 bundlerepo: use less intrusive util.posixfile to open bundle
Adrian Buehlmann <adrian@cadifra.com>
parents: 12962
diff changeset
174 f = util.posixfile(bundlename, "rb")
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
175 self.bundle = changegroup.readbundle(f, bundlename)
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
176 if self.bundle.compressed():
2273
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
177 fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-",
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
178 suffix=".hg10un", dir=self.path)
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
179 self.tempfile = temp
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
180 fptemp = os.fdopen(fdtemp, 'wb')
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
181
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
182 try:
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
183 fptemp.write("HG10UN")
12044
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 11154
diff changeset
184 while 1:
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
185 chunk = self.bundle.read(2**18)
12044
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 11154
diff changeset
186 if not chunk:
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 11154
diff changeset
187 break
2273
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
188 fptemp.write(chunk)
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
189 finally:
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
190 fptemp.close()
f116ddea537f add support for compressed bundle repositories
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2257
diff changeset
191
13274
57d433f632b7 bundlerepo: use less intrusive util.posixfile to open bundle
Adrian Buehlmann <adrian@cadifra.com>
parents: 12962
diff changeset
192 f = util.posixfile(self.tempfile, "rb")
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
193 self.bundle = changegroup.readbundle(f, bundlename)
12044
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 11154
diff changeset
194
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
195 # dict with the mapping 'filename' -> position in the bundle
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
196 self.bundlefilespos = {}
5262
a35756389ef4 Make bundlerepo lazier
Brendan Cully <brendan@kublai.com>
parents: 5167
diff changeset
197
8260
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
198 @util.propertycache
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
199 def changelog(self):
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
200 # consume the header if it exists
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
201 self.bundle.changelogheader()
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
202 c = bundlechangelog(self.sopener, self.bundle)
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
203 self.manstart = self.bundle.tell()
8260
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
204 return c
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
205
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
206 @util.propertycache
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
207 def manifest(self):
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
208 self.bundle.seek(self.manstart)
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
209 # consume the header if it exists
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
210 self.bundle.manifestheader()
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
211 m = bundlemanifest(self.sopener, self.bundle, self.changelog.rev)
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
212 self.filestart = self.bundle.tell()
8260
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
213 return m
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
214
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
215 @util.propertycache
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
216 def manstart(self):
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
217 self.changelog
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
218 return self.manstart
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
219
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
220 @util.propertycache
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
221 def filestart(self):
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
222 self.manifest
54a4b520bd7d localrepo: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
223 return self.filestart
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
224
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2273
diff changeset
225 def url(self):
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2273
diff changeset
226 return self._url
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2273
diff changeset
227
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
228 def file(self, f):
5262
a35756389ef4 Make bundlerepo lazier
Brendan Cully <brendan@kublai.com>
parents: 5167
diff changeset
229 if not self.bundlefilespos:
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
230 self.bundle.seek(self.filestart)
5262
a35756389ef4 Make bundlerepo lazier
Brendan Cully <brendan@kublai.com>
parents: 5167
diff changeset
231 while 1:
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
232 chunkdata = self.bundle.filelogheader()
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
233 if not chunkdata:
5262
a35756389ef4 Make bundlerepo lazier
Brendan Cully <brendan@kublai.com>
parents: 5167
diff changeset
234 break
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
235 fname = chunkdata['filename']
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
236 self.bundlefilespos[fname] = self.bundle.tell()
12335
e21fe9c5fb25 bundle: get rid of chunkiter
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
237 while 1:
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14142
diff changeset
238 c = self.bundle.deltachunk(None)
12335
e21fe9c5fb25 bundle: get rid of chunkiter
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
239 if not c:
e21fe9c5fb25 bundle: get rid of chunkiter
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
240 break
5262
a35756389ef4 Make bundlerepo lazier
Brendan Cully <brendan@kublai.com>
parents: 5167
diff changeset
241
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
242 if f[0] == '/':
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
243 f = f[1:]
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
244 if f in self.bundlefilespos:
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
245 self.bundle.seek(self.bundlefilespos[f])
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12331
diff changeset
246 return bundlefilelog(self.sopener, f, self.bundle,
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
247 self.changelog.rev)
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
248 else:
3791
8643b9f90b51 introduce localrepo.spath for the store path, sopener fixes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3787
diff changeset
249 return filelog.filelog(self.sopener, f)
1942
9da45de3118d add bundlerepo.py: a read-only repo that can use uncompressed bundles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
250
12347
6277a9469dff bundlerepo: restore close() method
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
251 def close(self):
6277a9469dff bundlerepo: restore close() method
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
252 """Close assigned bundle file immediately."""
6277a9469dff bundlerepo: restore close() method
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
253 self.bundle.close()
12962
ff083040a555 bundlerepository: get rid of temporary bundle files (issue2478)
Klaus Koch <kuk42@gmx.net>
parents: 12961
diff changeset
254 if self.tempfile is not None:
ff083040a555 bundlerepository: get rid of temporary bundle files (issue2478)
Klaus Koch <kuk42@gmx.net>
parents: 12961
diff changeset
255 os.unlink(self.tempfile)
6314
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
256 if self._tempparent:
9a1c59283ad3 Add ability to directly clone from all-history bundles
John Mulligan <phlogistonjohn@asynchrono.us>
parents: 6312
diff changeset
257 shutil.rmtree(self._tempparent, True)
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
258
6315
5c96a4bca66b clone: use cancopy
Matt Mackall <mpm@selenic.com>
parents: 6314
diff changeset
259 def cancopy(self):
5c96a4bca66b clone: use cancopy
Matt Mackall <mpm@selenic.com>
parents: 6314
diff changeset
260 return False
5c96a4bca66b clone: use cancopy
Matt Mackall <mpm@selenic.com>
parents: 6314
diff changeset
261
7435
5e13df32fb74 bundlerepo doesn't really have a dirstate, throw AttributeError if requested
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6953
diff changeset
262 def getcwd(self):
5e13df32fb74 bundlerepo doesn't really have a dirstate, throw AttributeError if requested
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6953
diff changeset
263 return os.getcwd() # always outside the repo
5e13df32fb74 bundlerepo doesn't really have a dirstate, throw AttributeError if requested
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6953
diff changeset
264
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
265 def instance(ui, path, create):
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
266 if create:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
267 raise util.Abort(_('cannot create new bundle repository'))
5664
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
268 parentpath = ui.config("bundle", "mainreporoot", "")
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
269 if parentpath:
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
270 # Try to make the full path relative so we get a nice, short URL.
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
271 # In particular, we don't want temp dir names in test outputs.
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
272 cwd = os.getcwd()
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
273 if parentpath == cwd:
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
274 parentpath = ''
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
275 else:
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
276 cwd = os.path.join(cwd,'')
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
277 if parentpath.startswith(cwd):
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
278 parentpath = parentpath[len(cwd):]
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 14073
diff changeset
279 u = util.url(path)
13826
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13742
diff changeset
280 path = u.localpath()
e574207e3bcd url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
Brodie Rao <brodie@bitheap.org>
parents: 13742
diff changeset
281 if u.scheme == 'bundle':
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
282 s = path.split("+", 1)
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
283 if len(s) == 1:
5664
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
284 repopath, bundlename = parentpath, s[0]
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
285 else:
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
286 repopath, bundlename = s
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
287 else:
5664
da72b4d24797 Fix income/pull with bundle and -R (issue 820).
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5558
diff changeset
288 repopath, bundlename = parentpath, path
2740
386f04d6ecb3 clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2673
diff changeset
289 return bundlerepository(ui, repopath, bundlename)
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
290
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
291 def getremotechanges(ui, repo, other, onlyheads=None, bundlename=None,
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14004
diff changeset
292 force=False):
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
293 '''obtains a bundle of changes incoming from other
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
294
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
295 "onlyheads" restricts the returned changes to those reachable from the
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
296 specified heads.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
297 "bundlename", if given, stores the bundle to this file path permanently;
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
298 the returned "bundle" will be None.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
299 "force" indicates whether to proceed on unrelated repos.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
300
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
301 Returns a tuple (local, csets, cleanupfn):
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
302
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
303 "local" is a local repo from which to obtain the actual incoming changesets; it
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
304 is a bundlerepo for the obtained bundle when the original "other" is remote.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
305 "csets" lists the incoming changeset node ids.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
306 "cleanupfn" must be called without arguments when you're done processing the
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
307 changes; it closes both the original "other" and the one returned here.
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
308 '''
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
309 tmp = discovery.findcommonincoming(repo, other, heads=onlyheads, force=force)
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
310 common, incoming, rheads = tmp
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
311 if not incoming:
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
312 try:
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
313 os.unlink(bundlename)
14004
97ed99d1f419 eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents: 13826
diff changeset
314 except OSError:
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
315 pass
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
316 return other, [], other.close
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
317
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
318 bundle = None
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
319 bundlerepo = None
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
320 localrepo = other
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
321 if bundlename or not other.local():
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
322 # create a bundle (uncompressed if other repo is not local)
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
323
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
324 if onlyheads is None and other.capable('changegroupsubset'):
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
325 onlyheads = rheads
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
326
14073
72c84f24b420 discovery: drop findoutgoing and simplify findcommonincoming's api
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14004
diff changeset
327 if other.capable('getbundle'):
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
328 cg = other.getbundle('incoming', common=common, heads=onlyheads)
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
329 elif onlyheads is None:
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
330 cg = other.changegroup(incoming, "incoming")
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
331 else:
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
332 cg = other.changegroupsubset(incoming, onlyheads, 'incoming')
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
333 bundletype = other.local() and "HG10BZ" or "HG10UN"
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
334 fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
335 # keep written bundle?
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
336 if bundlename:
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
337 bundle = None
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
338 if not other.local():
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
339 # use the created uncompressed bundlerepo
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
340 localrepo = bundlerepo = bundlerepository(ui, repo.root, fname)
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
341 # this repo contains local and other now, so filter out local again
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
342 common = repo.heads()
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
343
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
344 csets = localrepo.changelog.findmissing(common, onlyheads)
12734
5dfd1c49dcc5 bundlerepo: unify common code into a new getremotechanges
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12347
diff changeset
345
14161
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
346 def cleanup():
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
347 if bundlerepo:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
348 bundlerepo.close()
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
349 if bundle:
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
350 os.unlink(bundle)
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
351 localrepo.close()
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
352
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
353 return (localrepo, csets, cleanup)
8a0fca925992 bundlerepo: fix and improve getremotechanges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14158
diff changeset
354