##// END OF EJS Templates
branchmap: cache open/closed branch head information...
Brodie Rao -
r20185:7d421951 default
parent child Browse files
Show More
@@ -11,7 +11,7 b' import util'
11
11
12 def _filename(repo):
12 def _filename(repo):
13 """name of a branchcache file for a given repo or repoview"""
13 """name of a branchcache file for a given repo or repoview"""
14 filename = "cache/branchheads"
14 filename = "cache/branch2"
15 if repo.filtername:
15 if repo.filtername:
16 filename = '%s-%s' % (filename, repo.filtername)
16 filename = '%s-%s' % (filename, repo.filtername)
17 return filename
17 return filename
@@ -39,11 +39,16 b' def read(repo):'
39 for l in lines:
39 for l in lines:
40 if not l:
40 if not l:
41 continue
41 continue
42 node, label = l.split(" ", 1)
42 node, state, label = l.split(" ", 2)
43 if state not in 'oc':
44 raise ValueError('invalid branch state')
43 label = encoding.tolocal(label.strip())
45 label = encoding.tolocal(label.strip())
44 if not node in repo:
46 if not node in repo:
45 raise ValueError('node %s does not exist' % node)
47 raise ValueError('node %s does not exist' % node)
46 partial.setdefault(label, []).append(bin(node))
48 node = bin(node)
49 partial.setdefault(label, []).append(node)
50 if state == 'c':
51 partial._closednodes.add(node)
47 except KeyboardInterrupt:
52 except KeyboardInterrupt:
48 raise
53 raise
49 except Exception, inst:
54 except Exception, inst:
@@ -102,21 +107,32 b' class branchcache(dict):'
102 The cache is serialized on disk in the following format:
107 The cache is serialized on disk in the following format:
103
108
104 <tip hex node> <tip rev number> [optional filtered repo hex hash]
109 <tip hex node> <tip rev number> [optional filtered repo hex hash]
105 <branch head hex node> <branch name>
110 <branch head hex node> <open/closed state> <branch name>
106 <branch head hex node> <branch name>
111 <branch head hex node> <open/closed state> <branch name>
107 ...
112 ...
108
113
109 The first line is used to check if the cache is still valid. If the
114 The first line is used to check if the cache is still valid. If the
110 branch cache is for a filtered repo view, an optional third hash is
115 branch cache is for a filtered repo view, an optional third hash is
111 included that hashes the hashes of all filtered revisions.
116 included that hashes the hashes of all filtered revisions.
117
118 The open/closed state is represented by a single letter 'o' or 'c'.
119 This field can be used to avoid changelog reads when determining if a
120 branch head closes a branch or not.
112 """
121 """
113
122
114 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev,
123 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev,
115 filteredhash=None):
124 filteredhash=None, closednodes=None):
116 super(branchcache, self).__init__(entries)
125 super(branchcache, self).__init__(entries)
117 self.tipnode = tipnode
126 self.tipnode = tipnode
118 self.tiprev = tiprev
127 self.tiprev = tiprev
119 self.filteredhash = filteredhash
128 self.filteredhash = filteredhash
129 # closednodes is a set of nodes that close their branch. If the branch
130 # cache has been updated, it may contain nodes that are no longer
131 # heads.
132 if closednodes is None:
133 self._closednodes = set()
134 else:
135 self._closednodes = closednodes
120
136
121 def _hashfiltered(self, repo):
137 def _hashfiltered(self, repo):
122 """build hash of revision filtered in the current cache
138 """build hash of revision filtered in the current cache
@@ -152,7 +168,8 b' class branchcache(dict):'
152
168
153 def copy(self):
169 def copy(self):
154 """return an deep copy of the branchcache object"""
170 """return an deep copy of the branchcache object"""
155 return branchcache(self, self.tipnode, self.tiprev, self.filteredhash)
171 return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,
172 self._closednodes)
156
173
157 def write(self, repo):
174 def write(self, repo):
158 try:
175 try:
@@ -163,7 +180,12 b' class branchcache(dict):'
163 f.write(" ".join(cachekey) + '\n')
180 f.write(" ".join(cachekey) + '\n')
164 for label, nodes in sorted(self.iteritems()):
181 for label, nodes in sorted(self.iteritems()):
165 for node in nodes:
182 for node in nodes:
166 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
183 if node in self._closednodes:
184 state = 'c'
185 else:
186 state = 'o'
187 f.write("%s %s %s\n" % (hex(node), state,
188 encoding.fromlocal(label)))
167 f.close()
189 f.close()
168 except (IOError, OSError, util.Abort):
190 except (IOError, OSError, util.Abort):
169 # Abort may be raise by read only opener
191 # Abort may be raise by read only opener
@@ -177,9 +199,13 b' class branchcache(dict):'
177 cl = repo.changelog
199 cl = repo.changelog
178 # collect new branch entries
200 # collect new branch entries
179 newbranches = {}
201 newbranches = {}
180 getbranch = cl.branch
202 getbranchinfo = cl.branchinfo
181 for r in revgen:
203 for r in revgen:
182 newbranches.setdefault(getbranch(r), []).append(cl.node(r))
204 branch, closesbranch = getbranchinfo(r)
205 node = cl.node(r)
206 newbranches.setdefault(branch, []).append(node)
207 if closesbranch:
208 self._closednodes.add(node)
183 # if older branchheads are reachable from new ones, they aren't
209 # if older branchheads are reachable from new ones, they aren't
184 # really branchheads. Note checking parents is insufficient:
210 # really branchheads. Note checking parents is insufficient:
185 # 1 (branch a) -> 2 (branch b) -> 3 (branch a)
211 # 1 (branch a) -> 2 (branch b) -> 3 (branch a)
@@ -342,9 +342,10 b' class changelog(revlog.revlog):'
342 text = "\n".join(l)
342 text = "\n".join(l)
343 return self.addrevision(text, transaction, len(self), p1, p2)
343 return self.addrevision(text, transaction, len(self), p1, p2)
344
344
345 def branch(self, rev):
345 def branchinfo(self, rev):
346 """return the branch of a revision
346 """return the branch name and open/close state of a revision
347
347
348 This function exists because creating a changectx object
348 This function exists because creating a changectx object
349 just to access this is costly."""
349 just to access this is costly."""
350 return encoding.tolocal(self.read(rev)[5].get("branch"))
350 extra = self.read(rev)[5]
351 return encoding.tolocal(extra.get("branch")), 'close' in extra
@@ -338,8 +338,8 b' def clone(ui, peeropts, source, dest=Non'
338 # Recomputing branch cache might be slow on big repos,
338 # Recomputing branch cache might be slow on big repos,
339 # so just copy it
339 # so just copy it
340 dstcachedir = os.path.join(destpath, 'cache')
340 dstcachedir = os.path.join(destpath, 'cache')
341 srcbranchcache = srcrepo.sjoin('cache/branchheads')
341 srcbranchcache = srcrepo.sjoin('cache/branch2')
342 dstbranchcache = os.path.join(dstcachedir, 'branchheads')
342 dstbranchcache = os.path.join(dstcachedir, 'branch2')
343 if os.path.exists(srcbranchcache):
343 if os.path.exists(srcbranchcache):
344 if not os.path.exists(dstcachedir):
344 if not os.path.exists(dstcachedir):
345 os.mkdir(dstcachedir)
345 os.mkdir(dstcachedir)
@@ -70,7 +70,7 b' Non store repo:'
70 .hg/00changelog.i
70 .hg/00changelog.i
71 .hg/00manifest.i
71 .hg/00manifest.i
72 .hg/cache
72 .hg/cache
73 .hg/cache/branchheads-served
73 .hg/cache/branch2-served
74 .hg/data
74 .hg/data
75 .hg/data/tst.d.hg
75 .hg/data/tst.d.hg
76 .hg/data/tst.d.hg/foo.i
76 .hg/data/tst.d.hg/foo.i
@@ -98,7 +98,7 b' Non fncache repo:'
98 .hg
98 .hg
99 .hg/00changelog.i
99 .hg/00changelog.i
100 .hg/cache
100 .hg/cache
101 .hg/cache/branchheads-served
101 .hg/cache/branch2-served
102 .hg/dirstate
102 .hg/dirstate
103 .hg/last-message.txt
103 .hg/last-message.txt
104 .hg/requires
104 .hg/requires
@@ -196,7 +196,7 b' r4 has hardlinks in the working dir (not'
196 $ nlinksdir r4
196 $ nlinksdir r4
197 2 r4/.hg/00changelog.i
197 2 r4/.hg/00changelog.i
198 2 r4/.hg/branch
198 2 r4/.hg/branch
199 2 r4/.hg/cache/branchheads-served
199 2 r4/.hg/cache/branch2-served
200 2 r4/.hg/dirstate
200 2 r4/.hg/dirstate
201 2 r4/.hg/hgrc
201 2 r4/.hg/hgrc
202 2 r4/.hg/last-message.txt
202 2 r4/.hg/last-message.txt
@@ -226,7 +226,7 b' Update back to revision 11 in r4 should '
226 $ nlinksdir r4
226 $ nlinksdir r4
227 2 r4/.hg/00changelog.i
227 2 r4/.hg/00changelog.i
228 1 r4/.hg/branch
228 1 r4/.hg/branch
229 2 r4/.hg/cache/branchheads-served
229 2 r4/.hg/cache/branch2-served
230 1 r4/.hg/dirstate
230 1 r4/.hg/dirstate
231 2 r4/.hg/hgrc
231 2 r4/.hg/hgrc
232 2 r4/.hg/last-message.txt
232 2 r4/.hg/last-message.txt
@@ -66,7 +66,7 b' new directories are setgid'
66 00700 ./.hg/
66 00700 ./.hg/
67 00600 ./.hg/00changelog.i
67 00600 ./.hg/00changelog.i
68 00770 ./.hg/cache/
68 00770 ./.hg/cache/
69 00660 ./.hg/cache/branchheads-served
69 00660 ./.hg/cache/branch2-served
70 00660 ./.hg/dirstate
70 00660 ./.hg/dirstate
71 00660 ./.hg/last-message.txt
71 00660 ./.hg/last-message.txt
72 00600 ./.hg/requires
72 00600 ./.hg/requires
@@ -111,7 +111,7 b' group can still write everything'
111 00770 ../push/.hg/
111 00770 ../push/.hg/
112 00660 ../push/.hg/00changelog.i
112 00660 ../push/.hg/00changelog.i
113 00770 ../push/.hg/cache/
113 00770 ../push/.hg/cache/
114 00660 ../push/.hg/cache/branchheads-base
114 00660 ../push/.hg/cache/branch2-base
115 00660 ../push/.hg/requires
115 00660 ../push/.hg/requires
116 00770 ../push/.hg/store/
116 00770 ../push/.hg/store/
117 00660 ../push/.hg/store/00changelog.i
117 00660 ../push/.hg/store/00changelog.i
@@ -1,13 +1,13 b''
1 $ branchcache=.hg/cache/branchheads
1 $ branchcache=.hg/cache/branch2
2
2
3 $ listbranchcaches() {
3 $ listbranchcaches() {
4 > for f in .hg/cache/branchheads*;
4 > for f in .hg/cache/branch2*;
5 > do echo === $f ===;
5 > do echo === $f ===;
6 > cat $f;
6 > cat $f;
7 > done;
7 > done;
8 > }
8 > }
9 $ purgebranchcaches() {
9 $ purgebranchcaches() {
10 > rm .hg/cache/branchheads*
10 > rm .hg/cache/branch2*
11 > }
11 > }
12
12
13 $ hg init t
13 $ hg init t
@@ -158,13 +158,13 b' Test for invalid branch cache:'
158 4:adf1a74a7f7b
158 4:adf1a74a7f7b
159
159
160 $ listbranchcaches
160 $ listbranchcaches
161 === .hg/cache/branchheads ===
161 === .hg/cache/branch2 ===
162 corrupted
162 corrupted
163 === .hg/cache/branchheads-served ===
163 === .hg/cache/branch2-served ===
164 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
164 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
165 c21617b13b220988e7a2e26290fbe4325ffa7139 bar
165 c21617b13b220988e7a2e26290fbe4325ffa7139 o bar
166 1c28f494dae69a2f8fc815059d257eccf3fcfe75 default
166 1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default
167 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 foo
167 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo
168
168
169 Push should update the branch cache:
169 Push should update the branch cache:
170
170
@@ -175,20 +175,20 b' Pushing just rev 0:'
175 $ hg push -qr 0 ../target
175 $ hg push -qr 0 ../target
176
176
177 $ (cd ../target/; listbranchcaches)
177 $ (cd ../target/; listbranchcaches)
178 === .hg/cache/branchheads-base ===
178 === .hg/cache/branch2-base ===
179 db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 0
179 db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 0
180 db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 default
180 db01e8ea3388fd3c7c94e1436ea2bd6a53d581c5 o default
181
181
182 Pushing everything:
182 Pushing everything:
183
183
184 $ hg push -qf ../target
184 $ hg push -qf ../target
185
185
186 $ (cd ../target/; listbranchcaches)
186 $ (cd ../target/; listbranchcaches)
187 === .hg/cache/branchheads-base ===
187 === .hg/cache/branch2-base ===
188 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
188 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 4
189 c21617b13b220988e7a2e26290fbe4325ffa7139 bar
189 c21617b13b220988e7a2e26290fbe4325ffa7139 o bar
190 1c28f494dae69a2f8fc815059d257eccf3fcfe75 default
190 1c28f494dae69a2f8fc815059d257eccf3fcfe75 o default
191 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 foo
191 adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6 o foo
192
192
193 Update with no arguments: tipmost revision of the current branch:
193 Update with no arguments: tipmost revision of the current branch:
194
194
@@ -175,28 +175,28 b' visible shared between the initial repo '
175
175
176 check that branch cache with "served" filter are properly computed and stored
176 check that branch cache with "served" filter are properly computed and stored
177
177
178 $ ls ../push-dest/.hg/cache/branchheads*
178 $ ls ../push-dest/.hg/cache/branch2*
179 ../push-dest/.hg/cache/branchheads-served
179 ../push-dest/.hg/cache/branch2-served
180 $ cat ../push-dest/.hg/cache/branchheads-served
180 $ cat ../push-dest/.hg/cache/branch2-served
181 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
181 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
182 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
182 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
183 6d6770faffce199f1fddd1cf87f6f026138cf061 default
183 6d6770faffce199f1fddd1cf87f6f026138cf061 o default
184 $ hg heads -R ../push-dest --template '{rev}:{node} {phase}\n' #update visible cache too
184 $ hg heads -R ../push-dest --template '{rev}:{node} {phase}\n' #update visible cache too
185 6:6d6770faffce199f1fddd1cf87f6f026138cf061 draft
185 6:6d6770faffce199f1fddd1cf87f6f026138cf061 draft
186 5:2713879da13d6eea1ff22b442a5a87cb31a7ce6a secret
186 5:2713879da13d6eea1ff22b442a5a87cb31a7ce6a secret
187 3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e draft
187 3:b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e draft
188 $ ls ../push-dest/.hg/cache/branchheads*
188 $ ls ../push-dest/.hg/cache/branch2*
189 ../push-dest/.hg/cache/branchheads-served
189 ../push-dest/.hg/cache/branch2-served
190 ../push-dest/.hg/cache/branchheads-visible
190 ../push-dest/.hg/cache/branch2-visible
191 $ cat ../push-dest/.hg/cache/branchheads-served
191 $ cat ../push-dest/.hg/cache/branch2-served
192 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
192 6d6770faffce199f1fddd1cf87f6f026138cf061 6 465891ffab3c47a3c23792f7dc84156e19a90722
193 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
193 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
194 6d6770faffce199f1fddd1cf87f6f026138cf061 default
194 6d6770faffce199f1fddd1cf87f6f026138cf061 o default
195 $ cat ../push-dest/.hg/cache/branchheads-visible
195 $ cat ../push-dest/.hg/cache/branch2-visible
196 6d6770faffce199f1fddd1cf87f6f026138cf061 6
196 6d6770faffce199f1fddd1cf87f6f026138cf061 6
197 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e default
197 b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e o default
198 2713879da13d6eea1ff22b442a5a87cb31a7ce6a default
198 2713879da13d6eea1ff22b442a5a87cb31a7ce6a o default
199 6d6770faffce199f1fddd1cf87f6f026138cf061 default
199 6d6770faffce199f1fddd1cf87f6f026138cf061 o default
200
200
201
201
202 Restore condition prior extra insertion.
202 Restore condition prior extra insertion.
@@ -274,18 +274,18 b' We keep it the test this way in case new'
274 7:c65502d4178782309ce0574c5ae6ee9485a9bafa default
274 7:c65502d4178782309ce0574c5ae6ee9485a9bafa default
275 6:c772a8b2dc17629cec88a19d09c926c4814b12c7 default
275 6:c772a8b2dc17629cec88a19d09c926c4814b12c7 default
276
276
277 $ cat $TESTTMP/b2/.hg/cache/branchheads-served
277 $ cat $TESTTMP/b2/.hg/cache/branch2-served
278 c65502d4178782309ce0574c5ae6ee9485a9bafa 7
278 c65502d4178782309ce0574c5ae6ee9485a9bafa 7
279 c772a8b2dc17629cec88a19d09c926c4814b12c7 default
279 c772a8b2dc17629cec88a19d09c926c4814b12c7 o default
280 c65502d4178782309ce0574c5ae6ee9485a9bafa default
280 c65502d4178782309ce0574c5ae6ee9485a9bafa o default
281
281
282 $ hg strip 4
282 $ hg strip 4
283 saved backup bundle to $TESTTMP/b2/.hg/strip-backup/8a5212ebc852-backup.hg (glob)
283 saved backup bundle to $TESTTMP/b2/.hg/strip-backup/8a5212ebc852-backup.hg (glob)
284
284
285 $ cat $TESTTMP/b2/.hg/cache/branchheads-served
285 $ cat $TESTTMP/b2/.hg/cache/branch2-served
286 c65502d4178782309ce0574c5ae6ee9485a9bafa 4
286 c65502d4178782309ce0574c5ae6ee9485a9bafa 4
287 2870ad076e541e714f3c2bc32826b5c6a6e5b040 default
287 2870ad076e541e714f3c2bc32826b5c6a6e5b040 o default
288 c65502d4178782309ce0574c5ae6ee9485a9bafa default
288 c65502d4178782309ce0574c5ae6ee9485a9bafa o default
289
289
290 $ hg heads --template="{rev}:{node} {branch}\n"
290 $ hg heads --template="{rev}:{node} {branch}\n"
291 4:c65502d4178782309ce0574c5ae6ee9485a9bafa default
291 4:c65502d4178782309ce0574c5ae6ee9485a9bafa default
General Comments 0
You need to be logged in to leave comments. Login now