hgext/absorb.py
changeset 48913 f254fc73d956
parent 48875 6000f5b25c9b
child 48946 642e31cb55f0
equal deleted inserted replaced
48912:a0674e916fb6 48913:f254fc73d956
   731             self.paths.append(path)
   731             self.paths.append(path)
   732             self.ctxaffected.update(fstate.ctxaffected)
   732             self.ctxaffected.update(fstate.ctxaffected)
   733 
   733 
   734     def apply(self):
   734     def apply(self):
   735         """apply fixups to individual filefixupstates"""
   735         """apply fixups to individual filefixupstates"""
   736         for path, state in pycompat.iteritems(self.fixupmap):
   736         for path, state in self.fixupmap.items():
   737             if self.ui.debugflag:
   737             if self.ui.debugflag:
   738                 self.ui.write(_(b'applying fixups to %s\n') % path)
   738                 self.ui.write(_(b'applying fixups to %s\n') % path)
   739             state.apply()
   739             state.apply()
   740 
   740 
   741     @property
   741     @property
   742     def chunkstats(self):
   742     def chunkstats(self):
   743         """-> {path: chunkstats}. collect chunkstats from filefixupstates"""
   743         """-> {path: chunkstats}. collect chunkstats from filefixupstates"""
   744         return {
   744         return {path: state.chunkstats for path, state in self.fixupmap.items()}
   745             path: state.chunkstats
       
   746             for path, state in pycompat.iteritems(self.fixupmap)
       
   747         }
       
   748 
   745 
   749     def commit(self):
   746     def commit(self):
   750         """commit changes. update self.finalnode, self.replacemap"""
   747         """commit changes. update self.finalnode, self.replacemap"""
   751         with self.repo.transaction(b'absorb') as tr:
   748         with self.repo.transaction(b'absorb') as tr:
   752             self._commitstack()
   749             self._commitstack()
   760         """print things like '1 of 2 chunk(s) applied'"""
   757         """print things like '1 of 2 chunk(s) applied'"""
   761         ui = self.ui
   758         ui = self.ui
   762         chunkstats = self.chunkstats
   759         chunkstats = self.chunkstats
   763         if ui.verbose:
   760         if ui.verbose:
   764             # chunkstats for each file
   761             # chunkstats for each file
   765             for path, stat in pycompat.iteritems(chunkstats):
   762             for path, stat in chunkstats.items():
   766                 if stat[0]:
   763                 if stat[0]:
   767                     ui.write(
   764                     ui.write(
   768                         _(b'%s: %d of %d chunk(s) applied\n')
   765                         _(b'%s: %d of %d chunk(s) applied\n')
   769                         % (path, stat[0], stat[1])
   766                         % (path, stat[0], stat[1])
   770                     )
   767                     )
   843 
   840 
   844     def _movebookmarks(self, tr):
   841     def _movebookmarks(self, tr):
   845         repo = self.repo
   842         repo = self.repo
   846         needupdate = [
   843         needupdate = [
   847             (name, self.replacemap[hsh])
   844             (name, self.replacemap[hsh])
   848             for name, hsh in pycompat.iteritems(repo._bookmarks)
   845             for name, hsh in repo._bookmarks.items()
   849             if hsh in self.replacemap
   846             if hsh in self.replacemap
   850         ]
   847         ]
   851         changes = []
   848         changes = []
   852         for name, hsh in needupdate:
   849         for name, hsh in needupdate:
   853             if hsh:
   850             if hsh:
   906         if ctx.extra().get(b'close'):
   903         if ctx.extra().get(b'close'):
   907             return False
   904             return False
   908         # ctx changes more files (not a subset of memworkingcopy)
   905         # ctx changes more files (not a subset of memworkingcopy)
   909         if not set(ctx.files()).issubset(set(memworkingcopy)):
   906         if not set(ctx.files()).issubset(set(memworkingcopy)):
   910             return False
   907             return False
   911         for path, content in pycompat.iteritems(memworkingcopy):
   908         for path, content in memworkingcopy.items():
   912             if path not in pctx or path not in ctx:
   909             if path not in pctx or path not in ctx:
   913                 return False
   910                 return False
   914             fctx = ctx[path]
   911             fctx = ctx[path]
   915             pfctx = pctx[path]
   912             pfctx = pctx[path]
   916             if pfctx.flags() != fctx.flags():
   913             if pfctx.flags() != fctx.flags():
   949         return obsolete.isenabled(self.repo, obsolete.createmarkersopt)
   946         return obsolete.isenabled(self.repo, obsolete.createmarkersopt)
   950 
   947 
   951     def _cleanupoldcommits(self):
   948     def _cleanupoldcommits(self):
   952         replacements = {
   949         replacements = {
   953             k: ([v] if v is not None else [])
   950             k: ([v] if v is not None else [])
   954             for k, v in pycompat.iteritems(self.replacemap)
   951             for k, v in self.replacemap.items()
   955         }
   952         }
   956         if replacements:
   953         if replacements:
   957             scmutil.cleanupnodes(
   954             scmutil.cleanupnodes(
   958                 self.repo, replacements, operation=b'absorb', fixphase=True
   955                 self.repo, replacements, operation=b'absorb', fixphase=True
   959             )
   956             )
   999     patchmap = defaultdict(lambda: [])  # {path: [(a1, a2, [bline])]}
   996     patchmap = defaultdict(lambda: [])  # {path: [(a1, a2, [bline])]}
  1000     for path, info in map(_parsechunk, chunks):
   997     for path, info in map(_parsechunk, chunks):
  1001         if not path or not info:
   998         if not path or not info:
  1002             continue
   999             continue
  1003         patchmap[path].append(info)
  1000         patchmap[path].append(info)
  1004     for path, patches in pycompat.iteritems(patchmap):
  1001     for path, patches in patchmap.items():
  1005         if path not in ctx or not patches:
  1002         if path not in ctx or not patches:
  1006             continue
  1003             continue
  1007         patches.sort(reverse=True)
  1004         patches.sort(reverse=True)
  1008         lines = mdiff.splitnewlines(ctx[path].data())
  1005         lines = mdiff.splitnewlines(ctx[path].data())
  1009         for a1, a2, blines in patches:
  1006         for a1, a2, blines in patches: