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 ) |
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 |