From c9c9ff674b4d3b9e11a0a7b5e3676bcf109f59ec Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Fri, 5 Dec 2014 14:23:32 -0200 Subject: [PATCH] Fix migration script to use original SHA1 from tempest's commits Use git log instead of git filter-branch - which rewrites the history - to get SHA1 from the commits that touch the files to be migrated from tempest to tempest_lib. Change-Id: I321d78390991eb90fbb4a176a12187b78edc9f31 Closes-bug: #1386782 --- tools/migrate_from_tempest.sh | 59 +++++------------------------------ 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/tools/migrate_from_tempest.sh b/tools/migrate_from_tempest.sh index 2bf02d1..4751d0b 100755 --- a/tools/migrate_from_tempest.sh +++ b/tools/migrate_from_tempest.sh @@ -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 -