git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] prune: honor --expire=never

From
ASAdam Simpkins <simpkins@facebook.com>
Date
Feb 27, 2010, 03:50 UTC
Message-ID
<1267242604-5215-1-git-send-email-simpkins@facebook.com>
In-Reply-To
<20100227012130.GA28452@facebook.com>

Previously, prune treated an expiration time of 0 to mean that no expire argument was supplied, and everything should be pruned. As a result, "prune --expire=never" would prune all unreachable objects, regardless of their timestamp.

prune can be called with --expire=never automatically by gc, when the gc.pruneExpire configuration is set to "never".

Signed-off-by: Adam Simpkins <simpkins@facebook.com>
---
 builtin-prune.c  |   25 +++++++++++--------------
 t/t5304-prune.sh |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/builtin-prune.c b/builtin-prune.c
index 4675f60..f22bcf6 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -18,13 +18,11 @@ static unsigned long expire;
 static int prune_tmp_object(const char *path, const char *filename)
 {
 	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;
-	}
+	struct stat st;
+	if (lstat(fullpath, &st))
+		return error("Could not stat '%s'", fullpath);
+	if (st.st_mtime > expire)
+		return 0;
 	printf("Removing stale temporary file %s\n", fullpath);
 	if (!show_only)
 		unlink_or_warn(fullpath);
@@ -34,13 +32,11 @@ static int prune_tmp_object(const char *path, const char *filename)
 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;
-	}
+	struct stat st;
+	if (lstat(fullpath, &st))
+		return error("Could not stat '%s'", fullpath);
+	if (st.st_mtime > expire)
+		return 0;
 	if (show_only || verbose) {
 		enum object_type type = sha1_object_info(sha1, NULL);
 		printf("%s %s\n", sha1_to_hex(sha1),
@@ -139,6 +135,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	};
 	char *s;
 
+	expire = (unsigned long)-1;
 	save_commit_buffer = 0;
 	read_replace_refs = 0;
 	init_revisions(&revs, prefix);
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index 3c6687a..e2ed13d 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -148,6 +148,38 @@ test_expect_success 'gc --prune=<date>' '
 
 '
 
+test_expect_success 'gc --prune=never' '
+
+	add_blob &&
+	git gc --prune=never &&
+	test -f $BLOB_FILE &&
+	git gc --prune=now &&
+	test ! -f $BLOB_FILE
+
+'
+
+test_expect_success 'gc respects gc.pruneExpire=never' '
+
+	git config gc.pruneExpire never &&
+	add_blob &&
+	git gc &&
+	test -f $BLOB_FILE &&
+	git config gc.pruneExpire now &&
+	git gc &&
+	test ! -f $BLOB_FILE
+
+'
+
+test_expect_success 'prune --expire=never' '
+
+	add_blob &&
+	git prune --expire=never &&
+	test -f $BLOB_FILE &&
+	git prune &&
+	test ! -f $BLOB_FILE
+
+'
+
 test_expect_success 'gc: prune old objects after local clone' '
 	add_blob &&
 	test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
-- 
1.6.3.3
Previous: Adam SimpkinsNext: Adam Simpkins
Message 4 of 6 in “prune: honor --expire=never”
  1. prune: honor --expire=neverAdam Simpkins, Feb 26, 2010
  2. Junio C HamanoFeb 27, 2010
  3. Adam SimpkinsFeb 27, 2010
  4. 1/3 prune: honor --expire=neverAdam Simpkins, Feb 27, 2010
  5. 2/3 reflog: honor gc.reflogexpire=neverAdam Simpkins, Feb 27, 2010
  6. 3/3 clean up parsing of expiration datesAdam Simpkins, Feb 27, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.