Skip to content

Help minimize export dumps differences when inspecting --dry-run results #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ operations; however:
import argparse
import collections
import fnmatch
import functools
import gettext
import io
import os
Expand Down Expand Up @@ -3942,7 +3943,29 @@ class RepoFilter(object):
continue
# Otherwise, record the change
new_file_changes[change.filename] = change
commit.file_changes = [v for k,v in sorted(new_file_changes.items())]

# Use the git fast-export sorting algorithm for filenames
# https://github.com/git/git/blob/14de3eb34435db79c6e7edc8082c302a26a8330a/builtin/fast-export.c#L444-L448
def depth_first(a, b):
fn_a = a[0]
fn_b = b[0]

# Sort 'd/e' before 'd'
# first compare common length, then if equal give priority to longer one
min_len = min(len(fn_a), len(fn_b))
# memcmp equivalent https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
cmp = (fn_a[:min_len] > fn_b[:min_len]) - (fn_a[:min_len] < fn_b[:min_len])
if cmp != 0: # different content
return cmp # return normal comparison
cmp = len(fn_b) - len(fn_a)
if cmp != 0: # different size
return cmp # longer one first

# 'R' (rename) entries last
cmp = (a[1].type == 'R') - (b[1].type == 'R')
return cmp
commit.file_changes = [v for k,v in sorted(new_file_changes.items(),
key=functools.cmp_to_key(depth_first))]

def _tweak_commit(self, commit, aux_info):
if self._args.replace_message:
Expand Down