3 #==============================================================================
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
23 while test -n "$1"; do
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 ;;
34 if printf '%s\n' "$1" |
grep -q ^
-; then
35 echo "$progname: $1: Unknown option" >&2
43 opt_verbose
=$
(($opt_verbose - $opt_quiet))
45 if test "$opt_help" = "1"; then
46 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
49 Create a list in the style of "git annex info" showing in which
50 repositories unused data is stored.
52 Usage: $progname [options]
57 Output sizes as bytes instead of SI units.
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.
64 Output information as JSON.
66 Be more quiet. Can be repeated to increase silence.
68 Increase level of verbosity. Can be repeated.
70 Print version information.
76 EMPTYTREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
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
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
100 git remote
rm origin
>&2
101 if test -n "$(git remote)"; then
102 echo $progname: Some remotes still exist
>&2
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
120 for f
in $
(cat $KEYSUNUSED); do \
121 ln -s .git
/annex
/objects
/$f $TMPGADIR/$f; \
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
131 git annex info
$bytes_str $TMPGADIR \
133 | perl
-pe 's/ \[\S+\]$//;'
137 if test "$opt_keep" = "1"; then
138 echo $progname: Keeping temporary clone
$TMPCLONE >&2
143 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :