-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff-ubuntu-pkvm.sh
executable file
·103 lines (87 loc) · 3.17 KB
/
diff-ubuntu-pkvm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Current remotes are
# git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git
# https://github.com/open-power-host-os/linux (branch powerkvm-v3.1.1)
BRANCH1=$1
BRANCH2=$2
CUR_DIR=`pwd`
# A lot of temorary files which will be deleted
export TMPDIR=`mktemp -d scratch.XXX --tmpdir`
COMMIT_BRANCH1=`mktemp commit1.XXX --tmpdir`
COMMIT_BRANCH2=`mktemp commit2.XXX --tmpdir`
BRANCH_LOG1=`mktemp branch_log1.XXX --tmpdir`
BRANCH_LOG2=`mktemp branch_log2.XXX --tmpdir`
COMMENTS_BRANCH2=`mktemp comments.XXX --tmpdir`
AUX_FILE=`mktemp aux_file.XXX --tmpdir`
# This function will be used in a trap to remove temporary files on exit.
function finish()
{
rm -rf $TMPDIR
echo "Temporary directory deleted."
}
function usage()
{
echo "Usage: $(basename $0) <branch1> <branch2>"
exit 1
}
# The function get_git_log finds a possible ancestor for the branches provided
# It then gets the whole log for the first one. The parcial log starting from
# the ancestor for the second one, leaving out (tries to) upstream commits.
function get_git_log()
{
MERGE_BASE=`git merge-base $BRANCH1 $BRANCH2`
git checkout $BRANCH1
git branch
git log --pretty=oneline | tr -s " " > $BRANCH_LOG1
echo "Branch $BRANCH1: log copied."
git checkout $BRANCH2
git branch
git log --grep="\([Cc]ommit\|[Bb]ased\ on\)\ [0-9a-f]\{40\}\ upstream" \
--grep="[Uu]pstream commit\ [0-9a-f]\{40\}" \
--invert-grep $MERGE_BASE..HEAD --pretty=oneline | \
tr -s " " > $BRANCH_LOG2
echo "Branch $BRANCH2: log copied."
}
# First, the function below will create 2 files.
# One with just the commit hashes and another with only the comment
# header. Then it will run fgrep from each over the log and output the
# difference to diff_commits-all.txt
# It will then get all the commits that revert other commits and remove
# both the removing and the removed ones.
function search_commit()
{
set +e
cut -f1 -d' ' $BRANCH_LOG2 > $COMMIT_BRANCH2
cut --fields=2- -d' ' $BRANCH_LOG2 > $COMMENTS_BRANCH2
fgrep -o -f $COMMIT_BRANCH2 $BRANCH_LOG1 > $AUX_FILE
fgrep -o -f $COMMENTS_BRANCH2 $BRANCH_LOG1 >> $AUX_FILE
# The sed below removes the Linux versions commits from the result.
fgrep -v -f $AUX_FILE $BRANCH_LOG2 | \
sed '/[a-f0-9]\{40\}\ Linux\ .\+/d' > diff_commits-all.txt
mkdir -p diff-reports
mv diff_commits-all.txt diff-reports
cd diff-reports
git checkout $BRANCH2
git log --grep="This\ reverts\ commit\ [0-9a-f]\{40\}" $MERGE_BASE..HEAD \
--pretty=format:%H > $AUX_FILE
sed ':a;N;$!ba;s/\n/ /g' $AUX_FILE | \
xargs git show -s > reverts-show
grep "This\ reverts\ commit\ [0-9a-f]\{40\}" reverts-show | \
grep -o '[0-9a-f]\{40\}' >> $AUX_FILE
fgrep -v -f $AUX_FILE diff_commits-all.txt > diff_commits-final.txt
git show -s `cut -f1 -d' ' diff_commits-final.txt | sed ':a;N;$!ba;s/\n/ /g'` > git-show-result.txt
set -e
}
if [ -z $1 ] || [ -z $2 ]; then
usage
exit 1
fi
# Trap that removes the temporary files on an exit event.
trap finish EXIT
get_git_log
search_commit
if [ $? -eq 0 ]
then
echo "Finished!"
echo "Results can be verified in file diff_commits-final.txt"
fi