Skip to content

Commit b5d72f0

Browse files
committed
Teach prune-packed to use the standard progress meter
Rather than reimplementing the progress meter logic and always showing 100 lines of output while pruning already packed objects we now use a delayed progress meter and only show it if there are enough objects to make us take a little while. Most users won't see the message anymore as it usually doesn't take very long to delete the already packed loose objects. This neatens the output of a git-gc or git-repack execution, which is especially important for a `git gc --auto` triggered from within another command. We perform the display_progress() call from within the very innermost loop in case we spend more than 1 second within any single object directory. This ensures that a progress_update event from the timer will still trigger in a timely fashion and allow the user to see the progress meter. While I'm in here I changed the message to be more descriptive of its actual task. "Removing unused objects" is a little scary for new users as they wonder where these unused objects came from and how they should avoid them. Truth is these objects aren't unused in the sense of what git-prune would call a dangling object, these are used but are just duplicates of things we have already stored in a packfile. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 9c60a96 commit b5d72f0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

builtin-prune-packed.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include "builtin.h"
22
#include "cache.h"
3+
#include "progress.h"
34

45
static const char prune_packed_usage[] =
56
"git-prune-packed [-n] [-q]";
67

78
#define DRY_RUN 01
89
#define VERBOSE 02
910

11+
static struct progress progress;
12+
1013
static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
1114
{
1215
struct dirent *de;
@@ -23,6 +26,8 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
2326
if (!has_sha1_pack(sha1, NULL))
2427
continue;
2528
memcpy(pathname + len, de->d_name, 38);
29+
if (opts == VERBOSE)
30+
display_progress(&progress, i + 1);
2631
if (opts & DRY_RUN)
2732
printf("rm -f %s\n", pathname);
2833
else if (unlink(pathname) < 0)
@@ -39,6 +44,11 @@ void prune_packed_objects(int opts)
3944
const char *dir = get_object_directory();
4045
int len = strlen(dir);
4146

47+
if (opts == VERBOSE)
48+
start_progress_delay(&progress,
49+
"Removing duplicate objects",
50+
256, 95, 2);
51+
4252
if (len > PATH_MAX - 42)
4353
die("impossible object directory");
4454
memcpy(pathname, dir, len);
@@ -49,16 +59,13 @@ void prune_packed_objects(int opts)
4959

5060
sprintf(pathname + len, "%02x/", i);
5161
d = opendir(pathname);
52-
if (opts == VERBOSE && (d || i == 255))
53-
fprintf(stderr, "Removing unused objects %d%%...\015",
54-
((i+1) * 100) / 256);
5562
if (!d)
5663
continue;
5764
prune_dir(i, d, pathname, len + 3, opts);
5865
closedir(d);
5966
}
6067
if (opts == VERBOSE)
61-
fprintf(stderr, "\nDone.\n");
68+
stop_progress(&progress);
6269
}
6370

6471
int cmd_prune_packed(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)