Merge "Fix migration script to use original SHA1 from tempest's commits"
This commit is contained in:
@@ -46,58 +46,15 @@ function count_commits {
|
||||
git clone $TEMPEST_GIT_URL $tmpdir
|
||||
cd $tmpdir
|
||||
|
||||
# Build the grep pattern for ignoring files that we want to keep
|
||||
keep_pattern="\($(echo $files | sed -e 's/ /\\|/g')\)"
|
||||
# Prune all other files in every commit
|
||||
pruner="git ls-files | grep -v \"$keep_pattern\" | git update-index --force-remove --stdin; git ls-files > /dev/stderr"
|
||||
# get only commits that touch our files
|
||||
commits="$(git log --format=format:%h --no-merges --follow -- $files)"
|
||||
# then their merge commits - which works fina since we merge commits
|
||||
# individually.
|
||||
merge_commits="$(git log --format=format:%h --merges --first-parent -- $files)"
|
||||
pattern="\n$(echo $commits $merge_commits | sed -e 's/ /\\|/g')"
|
||||
|
||||
# Find all first commits with listed files and find a subset of them that
|
||||
# predates all others
|
||||
roots=""
|
||||
for file in $files; do
|
||||
file_root="$(git rev-list --reverse HEAD -- $file | head -n1)"
|
||||
fail=0
|
||||
for root in $roots; do
|
||||
if git merge-base --is-ancestor $root $file_root; then
|
||||
fail=1
|
||||
break
|
||||
elif ! git merge-base --is-ancestor $file_root $root; then
|
||||
new_roots="$new_roots $root"
|
||||
fi
|
||||
done
|
||||
if [ $fail -ne 1 ]; then
|
||||
roots="$new_roots $file_root"
|
||||
fi
|
||||
done
|
||||
|
||||
set_roots="
|
||||
if [ '' $(for root in $roots; do echo " -o \"\$GIT_COMMIT\" == '$root' "; done) ]; then
|
||||
echo ''
|
||||
else
|
||||
cat
|
||||
fi"
|
||||
|
||||
# Enhance git_commit_non_empty_tree to skip merges with:
|
||||
# a) either two equal parents (commit that was about to land got purged as well
|
||||
# as all commits on mainline);
|
||||
# b) or with second parent being an ancestor to the first one (just as with a)
|
||||
# but when there are some commits on mainline).
|
||||
# In both cases drop second parent and let git_commit_non_empty_tree to decide
|
||||
# if commit worth doing (most likely not).
|
||||
|
||||
skip_empty=$(cat << \EOF
|
||||
if [ $# = 5 ] && git merge-base --is-ancestor $5 $3; then
|
||||
git_commit_non_empty_tree $1 -p $3
|
||||
else
|
||||
git_commit_non_empty_tree "$@"
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
# Prune just the commits relevant to what is being migrated
|
||||
git filter-branch --index-filter "$pruner" --parent-filter "$set_roots" --commit-filter "$skip_empty" HEAD
|
||||
|
||||
SHA1_LIST=`git log --oneline`
|
||||
# order them by filtering each one in the order it appears on rev-list
|
||||
SHA1_LIST=$(git rev-list --oneline HEAD | grep $pattern)
|
||||
|
||||
# Move files and commit
|
||||
cd -
|
||||
|
Reference in New Issue
Block a user