##// END OF EJS Templates
revlog: extend addgroup() with callback for duplicates...
Joerg Sonnenberger -
r46373:a5206e71 default
parent child Browse files
Show More
@@ -674,9 +674,10 b' class sqlitefilestore(object):'
674 linkmapper,
674 linkmapper,
675 transaction,
675 transaction,
676 addrevisioncb=None,
676 addrevisioncb=None,
677 duplicaterevisioncb=None,
677 maybemissingparents=False,
678 maybemissingparents=False,
678 ):
679 ):
679 nodes = []
680 empty = True
680
681
681 for node, p1, p2, linknode, deltabase, delta, wireflags in deltas:
682 for node, p1, p2, linknode, deltabase, delta, wireflags in deltas:
682 storeflags = 0
683 storeflags = 0
@@ -715,8 +716,6 b' class sqlitefilestore(object):'
715
716
716 linkrev = linkmapper(linknode)
717 linkrev = linkmapper(linknode)
717
718
718 nodes.append(node)
719
720 if node in self._revisions:
719 if node in self._revisions:
721 # Possibly reset parents to make them proper.
720 # Possibly reset parents to make them proper.
722 entry = self._revisions[node]
721 entry = self._revisions[node]
@@ -741,6 +740,9 b' class sqlitefilestore(object):'
741 (self._nodetorev[p1], entry.flags, entry.rid),
740 (self._nodetorev[p1], entry.flags, entry.rid),
742 )
741 )
743
742
743 if duplicaterevisioncb:
744 duplicaterevisioncb(self, node)
745 empty = False
744 continue
746 continue
745
747
746 if deltabase == nullid:
748 if deltabase == nullid:
@@ -763,8 +765,9 b' class sqlitefilestore(object):'
763
765
764 if addrevisioncb:
766 if addrevisioncb:
765 addrevisioncb(self, node)
767 addrevisioncb(self, node)
768 empty = False
766
769
767 return nodes
770 return not empty
768
771
769 def censorrevision(self, tr, censornode, tombstone=b''):
772 def censorrevision(self, tr, censornode, tombstone=b''):
770 tombstone = storageutil.packmeta({b'censored': tombstone}, b'')
773 tombstone = storageutil.packmeta({b'censored': tombstone}, b'')
@@ -316,20 +316,29 b' class cg1unpacker(object):'
316 self.callback = progress.increment
316 self.callback = progress.increment
317
317
318 efilesset = set()
318 efilesset = set()
319 cgnodes = []
319
320
320 def onchangelog(cl, node):
321 def onchangelog(cl, node):
321 efilesset.update(cl.readfiles(node))
322 efilesset.update(cl.readfiles(node))
323 cgnodes.append(node)
324
325 def ondupchangelog(cl, node):
326 cgnodes.append(node)
322
327
323 self.changelogheader()
328 self.changelogheader()
324 deltas = self.deltaiter()
329 deltas = self.deltaiter()
325 cgnodes = cl.addgroup(deltas, csmap, trp, addrevisioncb=onchangelog)
330 if not cl.addgroup(
326 efiles = len(efilesset)
331 deltas,
327
332 csmap,
328 if not cgnodes:
333 trp,
334 addrevisioncb=onchangelog,
335 duplicaterevisioncb=ondupchangelog,
336 ):
329 repo.ui.develwarn(
337 repo.ui.develwarn(
330 b'applied empty changelog from changegroup',
338 b'applied empty changelog from changegroup',
331 config=b'warn-empty-changegroup',
339 config=b'warn-empty-changegroup',
332 )
340 )
341 efiles = len(efilesset)
333 clend = len(cl)
342 clend = len(cl)
334 changesets = clend - clstart
343 changesets = clend - clstart
335 progress.complete()
344 progress.complete()
@@ -343,16 +343,21 b' def _processchangesetdata(repo, tr, objs'
343 )
343 )
344
344
345 manifestnodes = {}
345 manifestnodes = {}
346 added = []
346
347
347 def linkrev(node):
348 def linkrev(node):
348 repo.ui.debug(b'add changeset %s\n' % short(node))
349 repo.ui.debug(b'add changeset %s\n' % short(node))
349 # Linkrev for changelog is always self.
350 # Linkrev for changelog is always self.
350 return len(cl)
351 return len(cl)
351
352
353 def ondupchangeset(cl, node):
354 added.append(node)
355
352 def onchangeset(cl, node):
356 def onchangeset(cl, node):
353 progress.increment()
357 progress.increment()
354
358
355 revision = cl.changelogrevision(node)
359 revision = cl.changelogrevision(node)
360 added.append(node)
356
361
357 # We need to preserve the mapping of changelog revision to node
362 # We need to preserve the mapping of changelog revision to node
358 # so we can set the linkrev accordingly when manifests are added.
363 # so we can set the linkrev accordingly when manifests are added.
@@ -403,8 +408,12 b' def _processchangesetdata(repo, tr, objs'
403 0,
408 0,
404 )
409 )
405
410
406 added = cl.addgroup(
411 cl.addgroup(
407 iterrevisions(), linkrev, weakref.proxy(tr), addrevisioncb=onchangeset
412 iterrevisions(),
413 linkrev,
414 weakref.proxy(tr),
415 addrevisioncb=onchangeset,
416 duplicaterevisioncb=ondupchangeset,
408 )
417 )
409
418
410 progress.complete()
419 progress.complete()
@@ -516,12 +525,15 b' def _fetchmanifests(repo, tr, remote, ma'
516 # Chomp off header object.
525 # Chomp off header object.
517 next(objs)
526 next(objs)
518
527
519 added.extend(
528 def onchangeset(cl, node):
529 added.append(node)
530
520 rootmanifest.addgroup(
531 rootmanifest.addgroup(
521 iterrevisions(objs, progress),
532 iterrevisions(objs, progress),
522 linkrevs.__getitem__,
533 linkrevs.__getitem__,
523 weakref.proxy(tr),
534 weakref.proxy(tr),
524 )
535 addrevisioncb=onchangeset,
536 duplicaterevisioncb=onchangeset,
525 )
537 )
526
538
527 progress.complete()
539 progress.complete()
@@ -139,6 +139,7 b' class filelog(object):'
139 linkmapper,
139 linkmapper,
140 transaction,
140 transaction,
141 addrevisioncb=None,
141 addrevisioncb=None,
142 duplicaterevisioncb=None,
142 maybemissingparents=False,
143 maybemissingparents=False,
143 ):
144 ):
144 if maybemissingparents:
145 if maybemissingparents:
@@ -150,7 +151,11 b' class filelog(object):'
150 )
151 )
151
152
152 return self._revlog.addgroup(
153 return self._revlog.addgroup(
153 deltas, linkmapper, transaction, addrevisioncb=addrevisioncb
154 deltas,
155 linkmapper,
156 transaction,
157 addrevisioncb=addrevisioncb,
158 duplicaterevisioncb=duplicaterevisioncb,
154 )
159 )
155
160
156 def getstrippoint(self, minlink):
161 def getstrippoint(self, minlink):
@@ -756,6 +756,7 b' class ifilemutation(interfaceutil.Interf'
756 linkmapper,
756 linkmapper,
757 transaction,
757 transaction,
758 addrevisioncb=None,
758 addrevisioncb=None,
759 duplicaterevisioncb=None,
759 maybemissingparents=False,
760 maybemissingparents=False,
760 ):
761 ):
761 """Process a series of deltas for storage.
762 """Process a series of deltas for storage.
@@ -1247,7 +1248,13 b' class imanifeststorage(interfaceutil.Int'
1247 See the documentation for ``ifiledata`` for more.
1248 See the documentation for ``ifiledata`` for more.
1248 """
1249 """
1249
1250
1250 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None):
1251 def addgroup(
1252 deltas,
1253 linkmapper,
1254 transaction,
1255 addrevisioncb=None,
1256 duplicaterevisioncb=None,
1257 ):
1251 """Process a series of deltas for storage.
1258 """Process a series of deltas for storage.
1252
1259
1253 See the documentation in ``ifilemutation`` for more.
1260 See the documentation in ``ifilemutation`` for more.
@@ -1832,9 +1832,20 b' class manifestrevlog(object):'
1832 deltamode=deltamode,
1832 deltamode=deltamode,
1833 )
1833 )
1834
1834
1835 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None):
1835 def addgroup(
1836 self,
1837 deltas,
1838 linkmapper,
1839 transaction,
1840 addrevisioncb=None,
1841 duplicaterevisioncb=None,
1842 ):
1836 return self._revlog.addgroup(
1843 return self._revlog.addgroup(
1837 deltas, linkmapper, transaction, addrevisioncb=addrevisioncb
1844 deltas,
1845 linkmapper,
1846 transaction,
1847 addrevisioncb=addrevisioncb,
1848 duplicaterevisioncb=duplicaterevisioncb,
1838 )
1849 )
1839
1850
1840 def rawsize(self, rev):
1851 def rawsize(self, rev):
@@ -2368,7 +2368,14 b' class revlog(object):'
2368 self._enforceinlinesize(transaction, ifh)
2368 self._enforceinlinesize(transaction, ifh)
2369 nodemaputil.setup_persistent_nodemap(transaction, self)
2369 nodemaputil.setup_persistent_nodemap(transaction, self)
2370
2370
2371 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None):
2371 def addgroup(
2372 self,
2373 deltas,
2374 linkmapper,
2375 transaction,
2376 addrevisioncb=None,
2377 duplicaterevisioncb=None,
2378 ):
2372 """
2379 """
2373 add a delta group
2380 add a delta group
2374
2381
@@ -2383,8 +2390,6 b' class revlog(object):'
2383 if self._writinghandles:
2390 if self._writinghandles:
2384 raise error.ProgrammingError(b'cannot nest addgroup() calls')
2391 raise error.ProgrammingError(b'cannot nest addgroup() calls')
2385
2392
2386 nodes = []
2387
2388 r = len(self)
2393 r = len(self)
2389 end = 0
2394 end = 0
2390 if r:
2395 if r:
@@ -2405,6 +2410,7 b' class revlog(object):'
2405 ifh.flush()
2410 ifh.flush()
2406
2411
2407 self._writinghandles = (ifh, dfh)
2412 self._writinghandles = (ifh, dfh)
2413 empty = True
2408
2414
2409 try:
2415 try:
2410 deltacomputer = deltautil.deltacomputer(self)
2416 deltacomputer = deltautil.deltacomputer(self)
@@ -2414,11 +2420,12 b' class revlog(object):'
2414 link = linkmapper(linknode)
2420 link = linkmapper(linknode)
2415 flags = flags or REVIDX_DEFAULT_FLAGS
2421 flags = flags or REVIDX_DEFAULT_FLAGS
2416
2422
2417 nodes.append(node)
2418
2419 if self.index.has_node(node):
2423 if self.index.has_node(node):
2424 # this can happen if two branches make the same change
2420 self._nodeduplicatecallback(transaction, node)
2425 self._nodeduplicatecallback(transaction, node)
2421 # this can happen if two branches make the same change
2426 if duplicaterevisioncb:
2427 duplicaterevisioncb(self, node)
2428 empty = False
2422 continue
2429 continue
2423
2430
2424 for p in (p1, p2):
2431 for p in (p1, p2):
@@ -2472,6 +2479,7 b' class revlog(object):'
2472
2479
2473 if addrevisioncb:
2480 if addrevisioncb:
2474 addrevisioncb(self, node)
2481 addrevisioncb(self, node)
2482 empty = False
2475
2483
2476 if not dfh and not self._inline:
2484 if not dfh and not self._inline:
2477 # addrevision switched from inline to conventional
2485 # addrevision switched from inline to conventional
@@ -2486,8 +2494,7 b' class revlog(object):'
2486 if dfh:
2494 if dfh:
2487 dfh.close()
2495 dfh.close()
2488 ifh.close()
2496 ifh.close()
2489
2497 return not empty
2490 return nodes
2491
2498
2492 def iscensored(self, rev):
2499 def iscensored(self, rev):
2493 """Check if a file revision is censored."""
2500 """Check if a file revision is censored."""
@@ -1117,7 +1117,22 b' class ifilemutationtests(basetestcase):'
1117 return 0
1117 return 0
1118
1118
1119 with self._maketransactionfn() as tr:
1119 with self._maketransactionfn() as tr:
1120 nodes = f.addgroup([], None, tr, addrevisioncb=cb)
1120 nodes = []
1121
1122 def onchangeset(cl, node):
1123 nodes.append(node)
1124 cb(cl, node)
1125
1126 def ondupchangeset(cl, node):
1127 nodes.append(node)
1128
1129 f.addgroup(
1130 [],
1131 None,
1132 tr,
1133 addrevisioncb=onchangeset,
1134 duplicaterevisioncb=ondupchangeset,
1135 )
1121
1136
1122 self.assertEqual(nodes, [])
1137 self.assertEqual(nodes, [])
1123 self.assertEqual(callbackargs, [])
1138 self.assertEqual(callbackargs, [])
@@ -1136,7 +1151,22 b' class ifilemutationtests(basetestcase):'
1136 ]
1151 ]
1137
1152
1138 with self._maketransactionfn() as tr:
1153 with self._maketransactionfn() as tr:
1139 nodes = f.addgroup(deltas, linkmapper, tr, addrevisioncb=cb)
1154 nodes = []
1155
1156 def onchangeset(cl, node):
1157 nodes.append(node)
1158 cb(cl, node)
1159
1160 def ondupchangeset(cl, node):
1161 nodes.append(node)
1162
1163 f.addgroup(
1164 deltas,
1165 linkmapper,
1166 tr,
1167 addrevisioncb=onchangeset,
1168 duplicaterevisioncb=ondupchangeset,
1169 )
1140
1170
1141 self.assertEqual(
1171 self.assertEqual(
1142 nodes,
1172 nodes,
@@ -1175,7 +1205,19 b' class ifilemutationtests(basetestcase):'
1175 deltas.append((nodes[i], nullid, nullid, nullid, nullid, delta, 0))
1205 deltas.append((nodes[i], nullid, nullid, nullid, nullid, delta, 0))
1176
1206
1177 with self._maketransactionfn() as tr:
1207 with self._maketransactionfn() as tr:
1178 self.assertEqual(f.addgroup(deltas, lambda x: 0, tr), nodes)
1208 newnodes = []
1209
1210 def onchangeset(cl, node):
1211 newnodes.append(node)
1212
1213 f.addgroup(
1214 deltas,
1215 lambda x: 0,
1216 tr,
1217 addrevisioncb=onchangeset,
1218 duplicaterevisioncb=onchangeset,
1219 )
1220 self.assertEqual(newnodes, nodes)
1179
1221
1180 self.assertEqual(len(f), len(deltas))
1222 self.assertEqual(len(f), len(deltas))
1181 self.assertEqual(list(f.revs()), [0, 1, 2])
1223 self.assertEqual(list(f.revs()), [0, 1, 2])
@@ -129,6 +129,7 b' class unionrevlog(revlog.revlog):'
129 linkmapper,
129 linkmapper,
130 transaction,
130 transaction,
131 addrevisioncb=None,
131 addrevisioncb=None,
132 duplicaterevisioncb=None,
132 maybemissingparents=False,
133 maybemissingparents=False,
133 ):
134 ):
134 raise NotImplementedError
135 raise NotImplementedError
@@ -532,6 +532,7 b' class filestorage(object):'
532 linkmapper,
532 linkmapper,
533 transaction,
533 transaction,
534 addrevisioncb=None,
534 addrevisioncb=None,
535 duplicaterevisioncb=None,
535 maybemissingparents=False,
536 maybemissingparents=False,
536 ):
537 ):
537 if maybemissingparents:
538 if maybemissingparents:
@@ -539,7 +540,7 b' class filestorage(object):'
539 _('simple store does not support missing parents ' 'write mode')
540 _('simple store does not support missing parents ' 'write mode')
540 )
541 )
541
542
542 nodes = []
543 empty = True
543
544
544 transaction.addbackup(self._indexpath)
545 transaction.addbackup(self._indexpath)
545
546
@@ -547,9 +548,10 b' class filestorage(object):'
547 linkrev = linkmapper(linknode)
548 linkrev = linkmapper(linknode)
548 flags = flags or revlog.REVIDX_DEFAULT_FLAGS
549 flags = flags or revlog.REVIDX_DEFAULT_FLAGS
549
550
550 nodes.append(node)
551
552 if node in self._indexbynode:
551 if node in self._indexbynode:
552 if duplicaterevisioncb:
553 duplicaterevisioncb(self, node)
554 empty = False
553 continue
555 continue
554
556
555 # Need to resolve the fulltext from the delta base.
557 # Need to resolve the fulltext from the delta base.
@@ -564,7 +566,8 b' class filestorage(object):'
564
566
565 if addrevisioncb:
567 if addrevisioncb:
566 addrevisioncb(self, node)
568 addrevisioncb(self, node)
567 return nodes
569 empty = False
570 return not empty
568
571
569 def _headrevs(self):
572 def _headrevs(self):
570 # Assume all revisions are heads by default.
573 # Assume all revisions are heads by default.
General Comments 0
You need to be logged in to leave comments. Login now