-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-ls-rev-files.sh
109 lines (102 loc) · 2.3 KB
/
git-ls-rev-files.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
104
105
106
107
108
109
#!/usr/bin/env bash
set -e
# Recursively list all files in the last 5 commits
revlist=$(git rev-list -5 HEAD)
(
echo 'git files: '
for rev in $revlist; do
files=$(git log -1 --pretty="format:" --name-only $rev)
echo "$(git log -1 --pretty="%s" $rev)"
echo ""
declare -A dir_tree
for file in $files; do
IFS='/'
read -ra ADDR <<<"$file"
path=""
for part in "${ADDR[@]}"; do
path="$path/$part"
dir_tree["$path"]=1
done
done
print_tree() {
local prefix="$1"
local level="${2:-0}"
local indent=""
for ((i = 0; i < level; i++)); do
indent="$indent "
done
for dir in "${!dir_tree[@]}"; do
if [[ "$dir" == "$prefix"* ]] && [[ "$dir" != "$prefix" ]] && [[ "$(dirname "$dir")" == "$prefix" ]]; then
echo "-$indent$(basename "$dir")"
print_tree "$dir" $((level + 1))
fi
done
}
print_tree "/"
done
) >___files_xml.txt
cat ___files_xml.txt
# non Recursively
# revlist=$(git rev-list -5 HEAD)
# {
# echo ""
# echo 'git files: '
# echo ""
# for rev in $revlist; do
# echo "$(git log -1 --pretty="%s" $rev)"
# files=$(git log -1 --pretty="format:" --name-only $rev)
# echo ""
#
# tempfile=$(mktemp)
#
# for file in $files; do
# IFS='/'
# read ra ADDR <<<"$file"
# path=""
# for part in "${ADDR[@]}"; do
# path="$path/$part"
# echo "$path" >>$tempfile
# done
# done
#
# sort -u "$tempfile" -o "$tempfile"
#
# # prev_indent_level=0
# prev_parts=()
# while IFS= read -r line; do
# [[ -z "$line" ]] && continue
# IFS='/' read -ra parts <<<"$line"
# indent_level=${#parts[@]}
#
# for ((i = 0; i < ${#parts[@]}; i++)); do
# indent=""
# for ((j = 0; j < i; j++)); do
# indent="$indent "
# done
# echo "$indent${parts[$i]}"
# done
# prev_parts=("${parts[@]}")
# done <"$tempfile"
#
# rm "$tempfile"
# done
# } >___files_xml.txt
#
# cat ___files_xml.txt
# base line
# revlist=$(git rev-list -5 HEAD)
# (
# echo '<?xml version="1.0"?>'
# echo '<git>'
# for rev in $revlist; do
# files=$(git log -1 --pretty="format:" --name-only $rev)
# echo ' <commit>\n <h1>\c'
# echo "$(git log -1 --pretty="%s" $rev)\c"
# echo '</h1>'
# for file in $files; do
# echo " <list>$file</list>"
# done
# echo ' </commit>'
# done
# echo '</git>'
# ) >___files_xml.txt