doc-diff: add --clean mode to remove temporary working gunk
As part of its operation, doc-diff creates a bunch of temporary working files and holds onto them in order to speed up subsequent invocations. These files are never deleted. Moreover, it creates a temporary working tree (via git-wortkree) which likewise never gets removed. Without knowing the implementation details of the tool, a user may not know how to clean up manually afterward. Worse, the user may find it surprising and alarming to discover a working tree which s/he did not create explicitly. To address these issues, add a --clean mode which removes the temporary working tree and deletes all generated files. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Aug 31, 2018 at 02:33 UTC
ad51743007d408ba6f1f670126d57722bb397ce6
1 file changed
+16
-3
Documentation/doc-diff
+16
-3
@@ -10,20 +10,25 @@
10
11
OPTIONS_SPEC="\
12
doc-diff [options] <from> <to> [-- <diff-options>]
13
+doc-diff (-c|--clean)
14
--
15
j=n parallel argument to pass to make
16
f force rebuild; do not rely on cached results
17
+c,clean cleanup temporary working files
18
"
19
SUBDIRECTORY_OK=1
20
. "$(git --exec-path)/git-sh-setup"
21
22
parallel=
23
force=
24
+clean=
25
while test $# -gt 0
26
do
27
case "$1" in
28
-j)
29
parallel=$2; shift ;;
30
+ -c|--clean)
31
+ clean=t ;;
32
-f)
33
force=t ;;
34
--)
@@ -34,6 +39,17 @@ do
39
shift
40
done
41
42
+cd_to_toplevel
43
+tmp=Documentation/tmp-doc-diff
44
+
45
+if test -n "$clean"
46
+then
47
+ test $# -eq 0 || usage
48
+ git worktree remove --force "$tmp/worktree" 2>/dev/null
49
+ rm -rf "$tmp"
50
+ exit 0
51
+fi
52
+
53
if test -z "$parallel"
54
then
55
parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
@@ -50,9 +66,6 @@ to=$1; shift
66
from_oid=$(git rev-parse --verify "$from") || exit 1
67
to_oid=$(git rev-parse --verify "$to") || exit 1
68
53
-cd_to_toplevel
54
-tmp=Documentation/tmp-doc-diff
55
-
69
if test -n "$force"
70
then
71
rm -rf "$tmp"