Skip to content

Commit

Permalink
filter-repo: wip towards second fast-export for notes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
newren committed Nov 26, 2024
1 parent 916c788 commit dfc2d00
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dfc2d00

Please sign in to comment.