mercurial/revlog.py
changeset 47084 27f1191b1305
parent 47078 223b47235d1c
child 47085 3aab2330b7d3
equal deleted inserted replaced
47083:81eb7091c494 47084:27f1191b1305
    83     stringutil,
    83     stringutil,
    84 )
    84 )
    85 
    85 
    86 # blanked usage of all the name to prevent pyflakes constraints
    86 # blanked usage of all the name to prevent pyflakes constraints
    87 # We need these name available in the module for extensions.
    87 # We need these name available in the module for extensions.
       
    88 
    88 REVLOGV0
    89 REVLOGV0
    89 REVLOGV1
    90 REVLOGV1
    90 REVLOGV2
    91 REVLOGV2
    91 FLAG_INLINE_DATA
    92 FLAG_INLINE_DATA
    92 FLAG_GENERALDELTA
    93 FLAG_GENERALDELTA
  1995                 _(b"attempted to add linkrev -1 to %s") % self.indexfile
  1996                 _(b"attempted to add linkrev -1 to %s") % self.indexfile
  1996             )
  1997             )
  1997 
  1998 
  1998         if sidedata is None:
  1999         if sidedata is None:
  1999             sidedata = {}
  2000             sidedata = {}
  2000         elif not self.hassidedata:
  2001         elif sidedata and not self.hassidedata:
  2001             raise error.ProgrammingError(
  2002             raise error.ProgrammingError(
  2002                 _(b"trying to add sidedata to a revlog who don't support them")
  2003                 _(b"trying to add sidedata to a revlog who don't support them")
  2003             )
  2004             )
  2004 
  2005 
  2005         if flags:
  2006         if flags:
  2656         tr,
  2657         tr,
  2657         destrevlog,
  2658         destrevlog,
  2658         addrevisioncb=None,
  2659         addrevisioncb=None,
  2659         deltareuse=DELTAREUSESAMEREVS,
  2660         deltareuse=DELTAREUSESAMEREVS,
  2660         forcedeltabothparents=None,
  2661         forcedeltabothparents=None,
  2661         sidedatacompanion=None,
  2662         sidedata_helpers=None,
  2662     ):
  2663     ):
  2663         """Copy this revlog to another, possibly with format changes.
  2664         """Copy this revlog to another, possibly with format changes.
  2664 
  2665 
  2665         The destination revlog will contain the same revisions and nodes.
  2666         The destination revlog will contain the same revisions and nodes.
  2666         However, it may not be bit-for-bit identical due to e.g. delta encoding
  2667         However, it may not be bit-for-bit identical due to e.g. delta encoding
  2699 
  2700 
  2700         In addition to the delta policy, the ``forcedeltabothparents``
  2701         In addition to the delta policy, the ``forcedeltabothparents``
  2701         argument controls whether to force compute deltas against both parents
  2702         argument controls whether to force compute deltas against both parents
  2702         for merges. By default, the current default is used.
  2703         for merges. By default, the current default is used.
  2703 
  2704 
  2704         If not None, the `sidedatacompanion` is callable that accept two
  2705         See `storageutil.emitrevisions` for the doc on `sidedata_helpers`.
  2705         arguments:
       
  2706 
       
  2707             (srcrevlog, rev)
       
  2708 
       
  2709         and return a quintet that control changes to sidedata content from the
       
  2710         old revision to the new clone result:
       
  2711 
       
  2712             (dropall, filterout, update, new_flags, dropped_flags)
       
  2713 
       
  2714         * if `dropall` is True, all sidedata should be dropped
       
  2715         * `filterout` is a set of sidedata keys that should be dropped
       
  2716         * `update` is a mapping of additionnal/new key -> value
       
  2717         * new_flags is a bitfields of new flags that the revision should get
       
  2718         * dropped_flags is a bitfields of new flags that the revision shoudl not longer have
       
  2719         """
  2706         """
  2720         if deltareuse not in self.DELTAREUSEALL:
  2707         if deltareuse not in self.DELTAREUSEALL:
  2721             raise ValueError(
  2708             raise ValueError(
  2722                 _(b'value for deltareuse invalid: %s') % deltareuse
  2709                 _(b'value for deltareuse invalid: %s') % deltareuse
  2723             )
  2710             )
  2753                 tr,
  2740                 tr,
  2754                 destrevlog,
  2741                 destrevlog,
  2755                 addrevisioncb,
  2742                 addrevisioncb,
  2756                 deltareuse,
  2743                 deltareuse,
  2757                 forcedeltabothparents,
  2744                 forcedeltabothparents,
  2758                 sidedatacompanion,
  2745                 sidedata_helpers,
  2759             )
  2746             )
  2760 
  2747 
  2761         finally:
  2748         finally:
  2762             destrevlog._lazydelta = oldlazydelta
  2749             destrevlog._lazydelta = oldlazydelta
  2763             destrevlog._lazydeltabase = oldlazydeltabase
  2750             destrevlog._lazydeltabase = oldlazydeltabase
  2768         tr,
  2755         tr,
  2769         destrevlog,
  2756         destrevlog,
  2770         addrevisioncb,
  2757         addrevisioncb,
  2771         deltareuse,
  2758         deltareuse,
  2772         forcedeltabothparents,
  2759         forcedeltabothparents,
  2773         sidedatacompanion,
  2760         sidedata_helpers,
  2774     ):
  2761     ):
  2775         """perform the core duty of `revlog.clone` after parameter processing"""
  2762         """perform the core duty of `revlog.clone` after parameter processing"""
  2776         deltacomputer = deltautil.deltacomputer(destrevlog)
  2763         deltacomputer = deltautil.deltacomputer(destrevlog)
  2777         index = self.index
  2764         index = self.index
  2778         for rev in self:
  2765         for rev in self:
  2784             linkrev = entry[4]
  2771             linkrev = entry[4]
  2785             p1 = index[entry[5]][7]
  2772             p1 = index[entry[5]][7]
  2786             p2 = index[entry[6]][7]
  2773             p2 = index[entry[6]][7]
  2787             node = entry[7]
  2774             node = entry[7]
  2788 
  2775 
  2789             sidedataactions = (False, [], {}, 0, 0)
       
  2790             if sidedatacompanion is not None:
       
  2791                 sidedataactions = sidedatacompanion(self, rev)
       
  2792 
       
  2793             # (Possibly) reuse the delta from the revlog if allowed and
  2776             # (Possibly) reuse the delta from the revlog if allowed and
  2794             # the revlog chunk is a delta.
  2777             # the revlog chunk is a delta.
  2795             cachedelta = None
  2778             cachedelta = None
  2796             rawtext = None
  2779             rawtext = None
  2797             if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD:
  2780             if deltareuse == self.DELTAREUSEFULLADD:
  2798                 dropall = sidedataactions[0]
       
  2799                 filterout = sidedataactions[1]
       
  2800                 update = sidedataactions[2]
       
  2801                 new_flags = sidedataactions[3]
       
  2802                 dropped_flags = sidedataactions[4]
       
  2803                 text, sidedata = self._revisiondata(rev)
  2781                 text, sidedata = self._revisiondata(rev)
  2804                 if dropall:
  2782 
  2805                     sidedata = {}
  2783                 if sidedata_helpers is not None:
  2806                 for key in filterout:
  2784                     (sidedata, new_flags) = storageutil.run_sidedata_helpers(
  2807                     sidedata.pop(key, None)
  2785                         self, sidedata_helpers, sidedata, rev
  2808                 sidedata.update(update)
  2786                     )
  2809                 if not sidedata:
  2787                     flags = flags | new_flags[0] & ~new_flags[1]
  2810                     sidedata = None
       
  2811 
       
  2812                 flags |= new_flags
       
  2813                 flags &= ~dropped_flags
       
  2814 
  2788 
  2815                 destrevlog.addrevision(
  2789                 destrevlog.addrevision(
  2816                     text,
  2790                     text,
  2817                     tr,
  2791                     tr,
  2818                     linkrev,
  2792                     linkrev,
  2828                 if destrevlog._lazydelta:
  2802                 if destrevlog._lazydelta:
  2829                     dp = self.deltaparent(rev)
  2803                     dp = self.deltaparent(rev)
  2830                     if dp != nullrev:
  2804                     if dp != nullrev:
  2831                         cachedelta = (dp, bytes(self._chunk(rev)))
  2805                         cachedelta = (dp, bytes(self._chunk(rev)))
  2832 
  2806 
       
  2807                 sidedata = None
  2833                 if not cachedelta:
  2808                 if not cachedelta:
  2834                     rawtext = self.rawdata(rev)
  2809                     rawtext, sidedata = self._revisiondata(rev)
       
  2810                 if sidedata is None:
       
  2811                     sidedata = self.sidedata(rev)
       
  2812 
       
  2813                 if sidedata_helpers is not None:
       
  2814                     (sidedata, new_flags) = storageutil.run_sidedata_helpers(
       
  2815                         self, sidedata_helpers, sidedata, rev
       
  2816                     )
       
  2817                     flags = flags | new_flags[0] & ~new_flags[1]
  2835 
  2818 
  2836                 ifh = destrevlog.opener(
  2819                 ifh = destrevlog.opener(
  2837                     destrevlog.indexfile, b'a+', checkambig=False
  2820                     destrevlog.indexfile, b'a+', checkambig=False
  2838                 )
  2821                 )
  2839                 dfh = None
  2822                 dfh = None
  2850                         flags,
  2833                         flags,
  2851                         cachedelta,
  2834                         cachedelta,
  2852                         ifh,
  2835                         ifh,
  2853                         dfh,
  2836                         dfh,
  2854                         deltacomputer=deltacomputer,
  2837                         deltacomputer=deltacomputer,
       
  2838                         sidedata=sidedata,
  2855                     )
  2839                     )
  2856                 finally:
  2840                 finally:
  2857                     if dfh:
  2841                     if dfh:
  2858                         dfh.close()
  2842                         dfh.close()
  2859                     ifh.close()
  2843                     ifh.close()