[PATCH] git-apply: Don't barf when --stat'ing a diff with no line changes.
[git.git] / git-deltafy-script
1 #!/bin/bash
2
3 # Example script to deltafy an entire GIT repository based on the commit list.
4 # The most recent version of a file is the reference and previous versions
5 # are made delta against the best earlier version available. And so on for
6 # successive versions going back in time.  This way the increasing delta
7 # overhead is pushed towards older versions of any given file.
8 #
9 # The -d argument allows to provide a limit on the delta chain depth.
10 # If 0 is passed then everything is undeltafied.  Limiting the delta
11 # depth is meaningful for subsequent access performance to old revisions.
12 # A value of 16 might be a good compromize between performance and good
13 # space saving.  Current default is unbounded.
14 #
15 # The --max-behind=30 argument is passed to git-mkdelta so to keep
16 # combinations and memory usage bounded a bit.  If you have lots of memory
17 # and CPU power you may remove it (or set to 0) to let git-mkdelta find the
18 # best delta match regardless of the number of revisions for a given file.
19 # You can also make the value smaller to make it faster and less
20 # memory hungry.  A value of 5 ought to still give pretty good results.
21 # When set to 0 or ommitted then look behind is unbounded.  Note that
22 # git-mkdelta might die with a segmentation fault in that case if it
23 # runs out of memory.  Note that the GIT repository will still be consistent
24 # even if git-mkdelta dies unexpectedly.
25
26 set -e
27
28 depth=
29 [ "$1" == "-d" ] && depth="--max-depth=$2" && shift 2
30
31 function process_list() {
32         if [ "$list" ]; then
33                 echo "Processing $curr_file"
34                 echo "$head $list" | xargs git-mkdelta $depth --max-behind=30 -v
35         fi
36 }
37
38 curr_file=""
39
40 git-rev-list HEAD |
41 git-diff-tree -r -t --stdin |
42 awk '/^:/ { if ($5 == "M" || $5 == "N") print $4, $6;
43             if ($5 == "M") print $3, $6 }' |
44 LC_ALL=C sort -s -k 2 | uniq |
45 while read sha1 file; do
46         if [ "$file" == "$curr_file" ]; then
47                 list="$list $sha1"
48         else
49                 process_list
50                 curr_file="$file"
51                 list=""
52                 head="$sha1"
53         fi
54 done
55 process_list
56
57 curr_file="root directory"
58 head=""
59 list="$(
60         git-rev-list HEAD |
61         while read commit; do
62                 git-cat-file commit $commit |
63                 sed -n 's/tree //p;Q'
64         done
65         )"
66 process_list
67