Skip to content

Commit b60daf0

Browse files
author
Junio C Hamano
committed
Make git-prune-packed a bit more chatty.
Steven Grimm noticed that git-repack's verbosity is inconsistent because pack-objects is chatty and prune-packed is not. This makes the latter a bit more chatty and gives -q option to squelch it. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f215f27 commit b60daf0

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Documentation/git-prune-packed.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ residing in a pack file.
99

1010
SYNOPSIS
1111
--------
12-
'git-prune-packed' [-n]
12+
'git-prune-packed' [-n] [-q]
1313

1414

1515
DESCRIPTION
@@ -32,6 +32,9 @@ OPTIONS
3232
Don't actually remove any objects, only show those that would have been
3333
removed.
3434

35+
-q::
36+
Squelch the progress indicator.
37+
3538
Author
3639
------
3740
Written by Linus Torvalds <torvalds@osdl.org>

builtin-prune-packed.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
static const char prune_packed_usage[] =
55
"git-prune-packed [-n]";
66

7-
static void prune_dir(int i, DIR *dir, char *pathname, int len, int dryrun)
7+
#define DRY_RUN 01
8+
#define VERBOSE 02
9+
10+
static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
811
{
912
struct dirent *de;
1013
char hex[40];
@@ -20,7 +23,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int dryrun)
2023
if (!has_sha1_pack(sha1, NULL))
2124
continue;
2225
memcpy(pathname + len, de->d_name, 38);
23-
if (dryrun)
26+
if (opts & DRY_RUN)
2427
printf("rm -f %s\n", pathname);
2528
else if (unlink(pathname) < 0)
2629
error("unable to unlink %s", pathname);
@@ -29,7 +32,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int dryrun)
2932
rmdir(pathname);
3033
}
3134

32-
void prune_packed_objects(int dryrun)
35+
void prune_packed_objects(int opts)
3336
{
3437
int i;
3538
static char pathname[PATH_MAX];
@@ -46,24 +49,31 @@ void prune_packed_objects(int dryrun)
4649

4750
sprintf(pathname + len, "%02x/", i);
4851
d = opendir(pathname);
52+
if (opts == VERBOSE && (d || i == 255))
53+
fprintf(stderr, "Removing unused objects %d%%...\015",
54+
((i+1) * 100) / 256);
4955
if (!d)
5056
continue;
51-
prune_dir(i, d, pathname, len + 3, dryrun);
57+
prune_dir(i, d, pathname, len + 3, opts);
5258
closedir(d);
5359
}
60+
if (opts == VERBOSE)
61+
fprintf(stderr, "\nDone.\n");
5462
}
5563

5664
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
5765
{
5866
int i;
59-
int dryrun = 0;
67+
int opts = VERBOSE;
6068

6169
for (i = 1; i < argc; i++) {
6270
const char *arg = argv[i];
6371

6472
if (*arg == '-') {
6573
if (!strcmp(arg, "-n"))
66-
dryrun = 1;
74+
opts |= DRY_RUN;
75+
else if (!strcmp(arg, "-q"))
76+
opts &= ~VERBOSE;
6777
else
6878
usage(prune_packed_usage);
6979
continue;
@@ -72,6 +82,6 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix)
7282
usage(prune_packed_usage);
7383
}
7484
sync();
75-
prune_packed_objects(dryrun);
85+
prune_packed_objects(opts);
7686
return 0;
7787
}

git-repack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ then
110110
done
111111
)
112112
fi
113-
git-prune-packed
113+
git-prune-packed $quiet
114114
fi
115115

116116
case "$no_update_info" in

0 commit comments

Comments
 (0)