static const char prune_usage[] = "git-prune [-n]";
static int show_only;
+static unsigned long expire;
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
{
- char buf[20];
- const char *type;
-
- if (show_only) {
- if (sha1_object_info(sha1, buf, NULL))
- type = "unknown";
- else
- type = buf;
- printf("%s %s\n", sha1_to_hex(sha1), type);
- return 0;
+ const char *fullpath = mkpath("%s/%s", path, filename);
+ if (expire) {
+ struct stat st;
+ if (lstat(fullpath, &st))
+ return error("Could not stat '%s'", fullpath);
+ if (st.st_mtime > expire)
+ return 0;
}
- unlink(mkpath("%s/%s", path, filename));
- rmdir(path);
+ if (show_only) {
+ enum object_type type = sha1_object_info(sha1, NULL);
+ printf("%s %s\n", sha1_to_hex(sha1),
+ (type > 0) ? typename(type) : "unknown");
+ } else
+ unlink(fullpath);
return 0;
}
}
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
}
+ if (!show_only)
+ rmdir(path);
closedir(dir);
return 0;
}
show_only = 1;
continue;
}
+ if (!strcmp(arg, "--expire")) {
+ if (++i < argc) {
+ expire = approxidate(argv[i]);
+ continue;
+ }
+ }
+ else if (!prefixcmp(arg, "--expire=")) {
+ expire = approxidate(arg + 9);
+ continue;
+ }
usage(prune_usage);
}