-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaven_diff_extractor.sh
More file actions
executable file
·52 lines (47 loc) · 1.87 KB
/
maven_diff_extractor.sh
File metadata and controls
executable file
·52 lines (47 loc) · 1.87 KB
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
#!/bin/bash
cd $3
foldername=`hg log -r $1 --template '{date|hgdate}' | awk -F ' ' '{print $1}'`_$2
mkdir -p $4/$foldername
#Adapted from http://stackoverflow.com/a/12179492/1871890
diff_lines() {
local path=
local line=
while read; do
esc=$'\033'
if [[ $REPLY =~ ---\ (a/)?.* ]]; then
continue
elif [[ $REPLY =~ \+\+\+\ (b/)?([^[:blank:]$esc]+).* ]]; then
path=${BASH_REMATCH[2]}
elif [[ $REPLY =~ @@\ -[0-9]+(,[0-9]+)?\ \+([0-9]+)(,[0-9]+)?\ @@.* ]]; then
line=${BASH_REMATCH[2]}
elif [[ $REPLY =~ ^($esc\[[0-9;]+m)*([\ +-]) ]]; then
echo "$line" >> $1/$foldername/$2/$3/$path.lines_changed
if [[ ${BASH_REMATCH[2]} != - ]]; then
((line++))
fi
fi
done
}
# extract the files impacted by $1 revision
# iterate over them
# extract commits impacting $file from beginning of the time and to revision $1
# then tail last 3 results (refers as $increment). They are the supposed to be
# 0) stable state before bug insertion
# 1) bug insertion - buggy state
# 2) bug fix, stable again
# iterate over the last three commit impacting current file
# create directories to host $file at $commit revision and
# sort them by $increment
# extract $file at $commit revision and place it in the right folder
# extract line impacted at $commit for $file with diff_lines and
# write them in the same directory as $file
increment=0
hg log -r $1 --style multiline \
| while read file ; do hg log $file -r "::$1" --template "{node|short}\n"| tail -n 3 \
| while read commit ; do \
mkdir -p $4/$foldername/$increment/$commit/"$(dirname "$file")" && \
hg cat $file -r $commit -o $4/$foldername/$increment/$commit/$file && \
hg log -p -r $commit $file | diff_lines $4 $increment $commit && \
(( increment++ )) \
; done \
; done