X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-prune.c;h=b5e768421ba548efaf0dd62ca876c15911df55d2;hb=95693d45ee1c1d4b76cac672636cf31229186a18;hp=09864b7a6d52bfb0855735418486e046438ecee4;hpb=27ebd6e0443bdd795869f598ecebc9eadd64a26c;p=git.git diff --git a/builtin-prune.c b/builtin-prune.c index 09864b7a6..b5e768421 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -7,17 +7,24 @@ 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) { + 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; + } 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"); - return 0; - } - unlink(mkpath("%s/%s", path, filename)); - rmdir(path); + } else + unlink(fullpath); return 0; } @@ -60,6 +67,8 @@ static int prune_dir(int i, char *path) } fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name); } + if (!show_only) + rmdir(path); closedir(dir); return 0; } @@ -85,6 +94,16 @@ int cmd_prune(int argc, const char **argv, const char *prefix) 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); }