git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: sbeller@google.com, peff@peff.net, jrnieder@gmail.com,
	avarab@gmail.com, jonathantanmy@google.com,
	Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH 01/11] repack: refactor pack deletion for future use
Date: Mon, 10 Jun 2019 16:35:22 -0700 (PDT)	[thread overview]
Message-ID: <3b424f7c2acafb400284089b218d2fb57f3192f2.1560209720.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.261.git.gitgitgadget@gmail.com>

From: Derrick Stolee <dstolee@microsoft.com>

The repack builtin deletes redundant pack-files and their
associated .idx, .promisor, .bitmap, and .keep files. We will want
to re-use this logic in the future for other types of repack, so
pull the logic into 'unlink_pack_path()' in packfile.c.

The 'ignore_keep' parameter is enabled for the use in repack, but
will be important for a future caller.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/repack.c | 14 ++------------
 packfile.c       | 28 ++++++++++++++++++++++++++++
 packfile.h       |  7 +++++++
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index 67f8978043..1f9e6fad1b 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -129,19 +129,9 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,
 
 static void remove_redundant_pack(const char *dir_name, const char *base_name)
 {
-	const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
-	int i;
 	struct strbuf buf = STRBUF_INIT;
-	size_t plen;
-
-	strbuf_addf(&buf, "%s/%s", dir_name, base_name);
-	plen = buf.len;
-
-	for (i = 0; i < ARRAY_SIZE(exts); i++) {
-		strbuf_setlen(&buf, plen);
-		strbuf_addstr(&buf, exts[i]);
-		unlink(buf.buf);
-	}
+	strbuf_addf(&buf, "%s/%s.pack", dir_name, base_name);
+	unlink_pack_path(buf.buf, 1);
 	strbuf_release(&buf);
 }
 
diff --git a/packfile.c b/packfile.c
index 060de420d1..683ce5674c 100644
--- a/packfile.c
+++ b/packfile.c
@@ -352,6 +352,34 @@ void close_all_packs(struct raw_object_store *o)
 	}
 }
 
+void unlink_pack_path(const char *pack_name, int force_delete)
+{
+	static const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
+	int i;
+	struct strbuf buf = STRBUF_INIT;
+	size_t plen;
+
+	strbuf_addstr(&buf, pack_name);
+	strip_suffix_mem(buf.buf, &buf.len, ".pack");
+	plen = buf.len;
+
+	if (!force_delete) {
+		strbuf_addstr(&buf, ".keep");
+		if (!access(buf.buf, F_OK)) {
+			strbuf_release(&buf);
+			return;
+		}
+	}
+
+	for (i = 0; i < ARRAY_SIZE(exts); i++) {
+		strbuf_setlen(&buf, plen);
+		strbuf_addstr(&buf, exts[i]);
+		unlink(buf.buf);
+	}
+
+	strbuf_release(&buf);
+}
+
 /*
  * The LRU pack is the one with the oldest MRU window, preferring packs
  * with no used windows, or the oldest mtime if it has no windows allocated.
diff --git a/packfile.h b/packfile.h
index 12baa6118a..09f5222113 100644
--- a/packfile.h
+++ b/packfile.h
@@ -94,6 +94,13 @@ void unuse_pack(struct pack_window **);
 void clear_delta_base_cache(void);
 struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
 
+/*
+ * Unlink the .pack and associated extension files.
+ * Does not unlink if 'force_delete' is false and the pack-file is
+ * marked as ".keep".
+ */
+extern void unlink_pack_path(const char *pack_name, int force_delete);
+
 /*
  * Make sure that a pointer access into an mmap'd index file is within bounds,
  * and can provide at least 8 bytes of data.
-- 
gitgitgadget


  reply	other threads:[~2019-06-10 23:35 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 23:35 [PATCH 00/11] Create 'expire' and 'repack' verbs for git-multi-pack-index Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` Derrick Stolee via GitGitGadget [this message]
2019-06-10 23:35 ` [PATCH 02/11] Docs: rearrange subcommands for multi-pack-index Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 03/11] multi-pack-index: prepare for 'expire' subcommand Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 05/11] midx: refactor permutation logic and pack sorting Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 04/11] midx: simplify computation of pack name lengths Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 06/11] multi-pack-index: implement 'expire' subcommand Derrick Stolee via GitGitGadget
2019-06-11 18:51   ` Junio C Hamano
2019-06-10 23:35 ` [PATCH 07/11] multi-pack-index: prepare 'repack' subcommand Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 08/11] midx: implement midx_repack() Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 09/11] multi-pack-index: test expire while adding packs Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 10/11] midx: add test that 'expire' respects .keep files Derrick Stolee via GitGitGadget
2019-06-10 23:35 ` [PATCH 11/11] t5319-multi-pack-index.sh: test batch size zero Derrick Stolee via GitGitGadget
2019-06-30 18:57 ` [PATCH] t5319: don't trip over a user name with whitespace Johannes Sixt
2019-06-30 19:48   ` Eric Sunshine
2019-06-30 20:59     ` Johannes Sixt
2019-06-30 22:25       ` Jeff King
2019-07-01  6:33         ` Johannes Sixt
2019-07-01  9:16           ` Jeff King
2019-07-01 11:33             ` SZEDER Gábor
2019-07-01 12:03               ` Derrick Stolee
2019-07-01 12:11         ` Johannes Schindelin
2019-07-01 12:30           ` Derrick Stolee
2019-07-01 18:22             ` Johannes Sixt
2019-07-01 18:47               ` Derrick Stolee
2019-07-01 12:53           ` Jeff King
2019-07-01  8:36       ` SZEDER Gábor
2019-07-01 17:17   ` Andreas Schwab
2019-07-01 19:24     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b424f7c2acafb400284089b218d2fb57f3192f2.1560209720.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).