Upgrade yt-dlp from version `stable@2024.05.27` to `stable@2024.07.09`
[sunny256-utils.git] / ga-find-exist
blob67e0f11468a9fbc024a8dc0d8e060dc8454ce5ba
1 #!/bin/sh
3 #==============================================================================
4 # ga-find-exist
5 # File ID: b3bc789e-fb2a-11e7-a332-f74d993421b0
7 # [Description]
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=ga-find-exist
14 VERSION=0.1.0
16 opt_help=0
17 opt_quiet=0
18 opt_verbose=0
19 while test -n "$1"; do
20 case "$1" in
21 -h|--help) opt_help=1; shift ;;
22 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
23 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
24 --version) echo $progname $VERSION; exit 0 ;;
25 --) shift; break ;;
27 if printf '%s\n' "$1" | grep -q ^-; then
28 echo "$progname: $1: Unknown option" >&2
29 exit 1
30 else
31 break
33 break ;;
34 esac
35 done
36 opt_verbose=$(($opt_verbose - $opt_quiet))
38 if test "$opt_help" = "1"; then
39 exname=big.iso
41 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
42 cat <<END
44 Usage: $progname [options] FILENAME
46 Go back in time in Git for a specific filename until FILENAME exists and
47 is not a broken symlink. Checks all earlier revisions where FILENAME was
48 modified. Abort if the git command fails.
50 Very suitable for git-annex, but can also be used with regular git. In
51 git-annex, it keeps scanning the history backwards until the symlink
52 isn't broken anymore. Can be used to find a reference file for rsync
53 transfers. If the files share common data, the transfer speed can be
54 increased dramatically. For example, transfer time for upgraded isofs
55 images can be reduced because not all files have changed, especially if
56 the files are stored in the same order as the previous version.
58 \$ $progname $exname # HEAD becomes detached if the file didn't exist
59 \$ git annex edit $exname
60 \$ rsync -avzL --progress user@remotehost:/path/to/$exname $exname
61 \$ git annex reinject --known $exname
62 \$ git checkout -f $exname # Was deleted by git annex reinject
63 \$ git checkout master
65 Returns 0 if FILENAME exists or it was found in the Git history.
66 Returns 1 if the git command failed or the file wasn't found.
68 Options:
70 -h, --help
71 Show this help.
72 -q, --quiet
73 Be more quiet. Can be repeated to increase silence.
74 -v, --verbose
75 Increase level of verbosity. Can be repeated.
76 --version
77 Print version information.
79 END
80 exit 0
83 file="$1"
85 if test -z "$file"; then
86 echo $progname: No file specified >&2
87 exit 1
90 test -e "$file" && exit 0
92 shas="$(git log --format=%h -- "$file")"
94 if test -z "$shas"; then
95 echo $progname: $file: File not found in the Git history >&2
96 exit 1
99 test $opt_verbose -ge 1 && echo $progname: Checking revisions $shas >&2
101 for s in $shas; do
102 git checkout $s || exit 1
103 test -e "$file" && exit 0
104 done
106 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :