-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathgit-dirt-filter
More file actions
executable file
·35 lines (31 loc) · 1003 Bytes
/
git-dirt-filter
File metadata and controls
executable file
·35 lines (31 loc) · 1003 Bytes
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
#! /bin/sh
DIRT_BRANCH_DEF="$(git rev-parse --show-toplevel)/branch.def"
current_branch="$(git branch | awk "/\*/ {print \$2}")"
if expr + "$current_branch" : ".*[^a-zA-Z0-9_-]" >/dev/null; then
current_branch_id=0
else
current_branch_id="$(awk "/$current_branch/ {print \$2}" < "$DIRT_BRANCH_DEF")"
fi
current_timestamp="$(git log -n 1 --pretty=format:%ct%n .)"
dirtfile="$(dirname "$2")/$(basename "$2" .in)"
exec 3> "${dirtfile}.new"
case "$1" in
--smudge)
while read line; do
echo "$line" | \
sed -e "s/DIRT_TIMESTAMP=.*/DIRT_TIMESTAMP=${current_timestamp:-0}/" \
-e "s/DIRT_BRANCH_ID=.*/DIRT_BRANCH_ID=${current_branch_id:-0}/"\
1>&3
echo "$line"
done
exec 3>&-
if [ -f "$dirtfile" ] && cmp -s "$dirtfile" "$dirtfile.new"; then
rm -f "$dirtfile".new
else
mv "$dirtfile.new" "$dirtfile"
fi
;;
--clean)
cat
;;
esac