std.h: Don't use `extern` in function prototypes
[sunny256-utils.git] / ga-infounused
blob605863693798a5a025120f90504bc15ac405b009
1 #!/bin/sh
3 #==============================================================================
4 # ga-infounused
5 # File ID: fce5f46e-c0a5-11ed-ae82-5582e081d110
7 # Create a list in the style of "git annex info" showing in which repositories
8 # unused data is stored.
10 # Author: Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later.
12 #==============================================================================
14 progname=ga-infounused
15 VERSION=0.1.1
17 opt_bytes=0
18 opt_help=0
19 opt_json=0
20 opt_keep=0
21 opt_quiet=0
22 opt_verbose=0
23 while test -n "$1"; do
24 case "$1" in
25 -b|--bytes) opt_bytes=1; shift ;;
26 -h|--help) opt_help=1; shift ;;
27 -j|--json) opt_json=1; shift ;;
28 -k|--keep) opt_keep=1; shift ;;
29 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
30 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
31 --version) echo $progname $VERSION; exit 0 ;;
32 --) shift; break ;;
34 if printf '%s\n' "$1" | grep -q ^-; then
35 echo "$progname: $1: Unknown option" >&2
36 exit 1
37 else
38 break
40 break ;;
41 esac
42 done
43 opt_verbose=$(($opt_verbose - $opt_quiet))
45 if test "$opt_help" = "1"; then
46 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
47 cat <<END
49 Create a list in the style of "git annex info" showing in which
50 repositories unused data is stored.
52 Usage: $progname [options]
54 Options:
56 -b/--bytes
57 Output sizes as bytes instead of SI units.
58 -h, --help
59 Show this help.
60 -k, --keep
61 Keep the temporary clone (stored in the top directory of the repo)
62 after exit. Useful if you want to have a look at the key lists.
63 -j/--json
64 Output information as JSON.
65 -q, --quiet
66 Be more quiet. Can be repeated to increase silence.
67 -v, --verbose
68 Increase level of verbosity. Can be repeated.
69 --version
70 Print version information.
72 END
73 exit 0
76 EMPTYTREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
77 KEYSALL=keys-all.txt
78 KEYSCURRENT=keys-current.txt
79 KEYSUNUSED=keys-unused.txt
80 TMPCLONE=.tmpclone.tmp
81 TMPGADIR=.tmpgadir.tmp
83 cd "$(git rev-parse --show-toplevel)" \
84 || { echo $progname: Cannot chdir to top of repo >&2; exit 1; }
86 if test -e $TMPCLONE -o -e $TMPCLONE.part; then
87 echo $progname: $TMPCLONE or $TMPCLONE.part already exist >&2
88 exit 1
91 git clone . $TMPCLONE.part >&2 \
92 || { echo $progname: Cannot clone current repo to $TMPCLONE >&2; exit 1; }
93 mv $TMPCLONE.part $TMPCLONE
94 cd $TMPCLONE || { echo $progname: $TMPCLONE: Cannot chdir >&2; exit 1; }
96 if ! git branch git-annex origin/git-annex >&2; then
97 echo $progname: Cannot create git-annex branch >&2
98 exit 1
100 git remote rm origin >&2
101 if test -n "$(git remote)"; then
102 echo $progname: Some remotes still exist >&2
103 exit 1
106 git ls-tree -r git-annex | ga-findkey -u | sort -u >$KEYSALL.new
107 mv $KEYSALL.new $KEYSALL
109 git diff --no-textconv HEAD $EMPTYTREE | grep \\.git/annex/objects/ \
110 | ga-findkey -u | sort -u >$KEYSCURRENT.new
111 mv $KEYSCURRENT.new $KEYSCURRENT
113 diff -u $KEYSALL $KEYSCURRENT | grep ^- | ga-findkey -u \
114 | sort -u >$KEYSUNUSED.new
115 mv $KEYSUNUSED.new $KEYSUNUSED
117 git annex init >&2
118 git annex merge >&2
119 mkdir $TMPGADIR
120 for f in $(cat $KEYSUNUSED); do \
121 ln -s .git/annex/objects/$f $TMPGADIR/$f; \
122 done
123 git add $TMPGADIR >&2
124 echo $(git annex fix $TMPGADIR 2>&1 | grep ^fix | wc -l) unused files >&2
126 test "$opt_bytes" = "1" && bytes_str=" --bytes" || bytes_str=""
128 if test "$opt_json" = "1"; then
129 git annex info$bytes_str -j $TMPGADIR
130 else
131 git annex info$bytes_str $TMPGADIR \
132 | grep " -- " \
133 | perl -pe 's/ \[\S+\]$//;'
136 cd ..
137 if test "$opt_keep" = "1"; then
138 echo $progname: Keeping temporary clone $TMPCLONE >&2
139 else
140 rm -rf $TMPCLONE
143 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :