From: James Melvin <jmelvin@codeaurora.org>
To: git@vger.kernel.org
Cc: nasserg@codeaurora.org, mfick@codeaurora.org, peff@peff.net,
sbeller@google.com, James Melvin <jmelvin@codeaurora.org>
Subject: [PATCH] repack: Add options to preserve and prune old pack files
Date: Tue, 7 Mar 2017 09:40:35 -0700 [thread overview]
Message-ID: <20170307164035.27866-1-jmelvin@codeaurora.org> (raw)
The new --preserve-oldpacks option moves old pack files into the
preserved subdirectory instead of deleting them after repacking.
The new --prune-preserved option prunes old pack files from the
preserved subdirectory after repacking, but before potentially
moving the latest old packfiles to this subdirectory.
These options are designed to prevent stale file handle exceptions
during git operations which can happen on users of NFS repos when
repacking is done on them. The strategy is to preserve old pack files
around until the next repack with the hopes that they will become
unreferenced by then and not cause any exceptions to running processes
when they are finally deleted (pruned).
Signed-off-by: James Melvin <jmelvin@codeaurora.org>
---
Documentation/git-repack.txt | 9 +++++++++
builtin/repack.c | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
index 26afe6ed5..0b19b761f 100644
--- a/Documentation/git-repack.txt
+++ b/Documentation/git-repack.txt
@@ -143,6 +143,15 @@ other objects in that pack they already have locally.
being removed. In addition, any unreachable loose objects will
be packed (and their loose counterparts removed).
+--preserve-oldpacks::
+ Move old pack files into the preserved subdirectory instead
+ of deleting them after repacking.
+
+--prune-preserved::
+ Prune old pack files from the preserved subdirectory after
+ repacking, but before potentially moving the latest old
+ packfiles to this subdirectory
+
Configuration
-------------
diff --git a/builtin/repack.c b/builtin/repack.c
index 677bc7c81..f1a0c97f3 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -10,8 +10,10 @@
static int delta_base_offset = 1;
static int pack_kept_objects = -1;
+static int preserve_oldpacks = 0;
+static int prune_preserved = 0;
static int write_bitmaps;
-static char *packdir, *packtmp;
+static char *packdir, *packtmp, *preservedir;
static const char *const git_repack_usage[] = {
N_("git repack [<options>]"),
@@ -108,6 +110,27 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
closedir(dir);
}
+static void preserve_pack(const char *file_path, const char *file_name, const char *file_ext)
+{
+ char *fname_old;
+
+ if (mkdir(preservedir, 0700) && errno != EEXIST)
+ error(_("failed to create preserve directory"));
+
+ fname_old = mkpathdup("%s/%s.old-%s", preservedir, file_name, ++file_ext);
+ rename(file_path, fname_old);
+
+ free(fname_old);
+}
+
+static void remove_preserved_dir(void) {
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addstr(&buf, preservedir);
+ remove_dir_recursively(&buf, 0);
+ strbuf_release(&buf);
+}
+
static void remove_redundant_pack(const char *dir_name, const char *base_name)
{
const char *exts[] = {".pack", ".idx", ".keep", ".bitmap"};
@@ -121,7 +144,10 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
for (i = 0; i < ARRAY_SIZE(exts); i++) {
strbuf_setlen(&buf, plen);
strbuf_addstr(&buf, exts[i]);
- unlink(buf.buf);
+ if (preserve_oldpacks)
+ preserve_pack(buf.buf, base_name, exts[i]);
+ else
+ unlink(buf.buf);
}
strbuf_release(&buf);
}
@@ -194,6 +220,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
N_("maximum size of each packfile")),
OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
N_("repack objects in packs marked with .keep")),
+ OPT_BOOL(0, "preserve-oldpacks", &preserve_oldpacks,
+ N_("move old pack files into the preserved subdirectory")),
+ OPT_BOOL(0, "prune-preserved", &prune_preserved,
+ N_("prune old pack files from the preserved subdirectory after repacking")),
OPT_END()
};
@@ -217,6 +247,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
packdir = mkpathdup("%s/pack", get_object_directory());
packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
+ preservedir = mkpathdup("%s/preserved", packdir);
sigchain_push_common(remove_pack_on_signal);
@@ -404,6 +435,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
/* End of pack replacement. */
+ if (prune_preserved)
+ remove_preserved_dir();
+
if (delete_redundant) {
int opts = 0;
string_list_sort(&names);
--
2.12.0.190.gab6997d48.dirty
next reply other threads:[~2017-03-07 16:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-07 16:40 James Melvin [this message]
2017-03-07 20:33 ` [PATCH] repack: Add options to preserve and prune old pack files Junio C Hamano
2017-03-09 17:50 ` jmelvin
2017-03-09 18:45 ` Martin Fick
2017-03-10 21:52 ` jmelvin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170307164035.27866-1-jmelvin@codeaurora.org \
--to=jmelvin@codeaurora.org \
--cc=git@vger.kernel.org \
--cc=mfick@codeaurora.org \
--cc=nasserg@codeaurora.org \
--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.
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 NNTP newsgroup(s).