diff options
author | Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com> | 2014-12-05 14:23:32 -0200 |
---|---|---|
committer | Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com> | 2014-12-05 14:31:58 -0200 |
commit | c9c9ff674b4d3b9e11a0a7b5e3676bcf109f59ec (patch) | |
tree | 4f34dd48b0e845aaa67b1d29481c3e02fff9f6da | |
parent | 5715fd65142380573c5cb1f0ff4f3996004b3466 (diff) | |
download | tempest-lib-c9c9ff674b4d3b9e11a0a7b5e3676bcf109f59ec.tar.gz |
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
-rwxr-xr-x | tools/migrate_from_tempest.sh | 61 |
1 files changed, 9 insertions, 52 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" - -# 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` +# 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')" + +# 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 - |