Skip to content

Commit 51890a6

Browse files
author
Junio C Hamano
committed
Call prune-packed from "git prune" as well.
Add -n (dryrun) flag to git-prune-packed, and call it from "git prune". Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 4426ac7 commit 51890a6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

git-prune-script

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
. git-sh-setup-script || die "Not a git archive"
44

55
dryrun=
6+
echo=
67
while case "$#" in 0) break ;; esac
78
do
89
case "$1" in
9-
-n) dryrun=echo ;;
10+
-n) dryrun=-n echo=echo ;;
1011
--) break ;;
1112
-*) echo >&2 "usage: git-prune-script [ -n ] [ heads... ]"; exit 1 ;;
1213
*) break ;;
@@ -20,6 +21,7 @@ sed -ne '/unreachable /{
2021
s|\(..\)|\1/|p
2122
}' | {
2223
cd "$GIT_OBJECT_DIRECTORY" || exit
23-
xargs $dryrun rm -f
24+
xargs $echo rm -f
2425
}
2526

27+
git-prune-packed $dryrun

prune-packed.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "cache.h"
22

3-
static const char prune_packed_usage[] = "git-prune-packed (no arguments)";
3+
static const char prune_packed_usage[] =
4+
"git-prune-packed [-n]";
5+
6+
static int dryrun;
47

58
static void prune_dir(int i, DIR *dir, char *pathname, int len)
69
{
@@ -18,7 +21,9 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len)
1821
if (!has_sha1_pack(sha1))
1922
continue;
2023
memcpy(pathname + len, de->d_name, 38);
21-
if (unlink(pathname) < 0)
24+
if (dryrun)
25+
printf("rm -f %s\n", pathname);
26+
else if (unlink(pathname) < 0)
2227
error("unable to unlink %s", pathname);
2328
}
2429
}
@@ -55,8 +60,11 @@ int main(int argc, char **argv)
5560
const char *arg = argv[i];
5661

5762
if (*arg == '-') {
58-
/* Handle flags here .. */
59-
usage(prune_packed_usage);
63+
if (!strcmp(arg, "-n"))
64+
dryrun = 1;
65+
else
66+
usage(prune_packed_usage);
67+
continue;
6068
}
6169
/* Handle arguments here .. */
6270
usage(prune_packed_usage);

0 commit comments

Comments
 (0)