From dfc2d00587845f2301c0961ceafa94b9ad861a91 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 25 Nov 2024 22:31:30 -0800 Subject: [PATCH] filter-repo: wip towards second fast-export for notes handling --- git-filter-repo | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index c0ad7bcb..17906d0c 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -3138,6 +3138,8 @@ class RepoFilter(object): # Defaults for input self._input = None + self._notes_input = None + self._notes_fep = None # Fast Export Process for refs/notes/ self._fep = None # Fast Export Process self._fe_orig = None # Path to where original fast-export output stored self._fe_filt = None # Path to where filtered fast-export output stored @@ -4318,6 +4320,7 @@ class RepoFilter(object): self._fe_orig = None else: self._read_stash() + notes_refs = [x for x in self._orig_refs if x.startswith(b'refs/notes/')] skip_blobs = (self._blob_callback is None and (self._args.replace_text is None or self._file_info_callback is not None) and @@ -4342,12 +4345,20 @@ class RepoFilter(object): if self._args.date_order: extra_flags.append('--date-order') location = ['-C', self._args.source] if self._args.source else [] + exclusion_refs = (['--not'] + notes_refs) if notes_refs else [] fep_cmd = ['git'] + location + ['fast-export', '--show-original-ids', '--signed-tags=strip', '--tag-of-filtered-object=rewrite', '--fake-missing-tagger', '--reference-excluded-parents' - ] + extra_flags + self._args.refs + ] + extra_flags + self._args.refs + exclusion_refs self._fep = subproc.Popen(fep_cmd, bufsize=-1, stdout=subprocess.PIPE) self._input = self._fep.stdout + if notes_refs: + notes_fep_cmd = ['git'] + location + ['fast-export', + '--show-original_ids', '--reference-excluded-parents' + ] + notes_refs + self._notes_fep = subproc.Popen(notes_fep_cmd, bufsize=-1, + stdout=subprocess.PIPE) + self._notes_input = self._notes_fep.stdout if self._args.dry_run or self._args.debug: self._fe_orig = os.path.join(self.results_tmp_dir(), b'fast-export.original') @@ -4358,6 +4369,11 @@ class RepoFilter(object): print("[DEBUG] Running: {}".format(' '.join(tmp))) print(" (saving a copy of the output at {})" .format(decode(self._fe_orig))) + if notes_refs: + notes_export_loc = os.path.join(self.results_tmp_dir(), + b'fast-export-notes.original') + output = open(notes_export_loc, 'bw') + self._notes_input = InputFileBackup(self._notes_input, output) def _setup_output(self): if not self._args.dry_run: @@ -4893,7 +4909,16 @@ class RepoFilter(object): raise SystemExit(_("Error: fast-export failed; see above.")) # pragma: no cover self._input.close() - # Do some final cleanup + # Run an additional filter + if self._notes_input: + self._input = self._notes_input + self._parser = FastExportParser(commit_callback = self._tweak_note, + reset_callback = self._tweak_reset) + self._parser.run(self._input, self._output) + if self._notes_fep.wait(): + raise SystemExit(_("Error: fast-export on notes failed; see above.")) # pragma: no cover + self._input.close() + if self._file_info_value: self._file_info_value.finalize() if not self._args.quiet: