From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Ramkumar Ramachandra" <artagnon@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] gc: reject if another gc is running, unless --force is given
Date: Sat, 3 Aug 2013 11:20:05 +0700 [thread overview]
Message-ID: <1375503605-32480-1-git-send-email-pclouds@gmail.com> (raw)
This may happen when `git gc --auto` is run automatically, then the
user, to avoid wait time, switches to a new terminal, keeps working
and `git gc --auto` is started again because the first gc instance has
not clean up the repository.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
I don't know if the kill(pid, 0) trick works on Windows..
Documentation/git-gc.txt | 6 +++++-
builtin/gc.c | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt
index 2402ed6..e158a3b 100644
--- a/Documentation/git-gc.txt
+++ b/Documentation/git-gc.txt
@@ -9,7 +9,7 @@ git-gc - Cleanup unnecessary files and optimize the local repository
SYNOPSIS
--------
[verse]
-'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
+'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force]
DESCRIPTION
-----------
@@ -72,6 +72,10 @@ automatic consolidation of packs.
--quiet::
Suppress all progress reports.
+--force::
+ Force `git gc` to run even if there may be another `git gc`
+ instance running on this repository.
+
Configuration
-------------
diff --git a/builtin/gc.c b/builtin/gc.c
index 6be6c8d..07c566c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -169,9 +169,11 @@ static int need_to_gc(void)
int cmd_gc(int argc, const char **argv, const char *prefix)
{
+ FILE *fp;
int aggressive = 0;
int auto_gc = 0;
int quiet = 0;
+ int force = 0;
struct option builtin_gc_options[] = {
OPT__QUIET(&quiet, N_("suppress progress reporting")),
@@ -180,6 +182,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },
OPT_BOOLEAN(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
OPT_BOOLEAN(0, "auto", &auto_gc, N_("enable auto-gc mode")),
+ OPT_BOOL(0, "force", &force, N_("force running gc even if there may be another gc running")),
OPT_END()
};
@@ -225,6 +228,21 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
} else
add_repack_all_option();
+ if (!force && (fp = fopen(git_path("gc.pid"), "r")) != NULL) {
+ uintmax_t pid;
+ if (fscanf(fp, "%"PRIuMAX, &pid) == 1 && !kill(pid, 0)) {
+ if (auto_gc)
+ return 0; /* be quiet on --auto */
+ die(_("gc is already running"));
+ }
+ fclose(fp);
+ }
+
+ if ((fp = fopen(git_path("gc.pid"), "w")) != NULL) {
+ fprintf(fp, "%"PRIuMAX"\n", (uintmax_t) getpid());
+ fclose(fp);
+ }
+
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
return error(FAILED_RUN, pack_refs_cmd.argv[0]);
--
1.8.2.83.gc99314b
next reply other threads:[~2013-08-03 4:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-03 4:20 Nguyễn Thái Ngọc Duy [this message]
2013-08-03 6:21 ` [PATCH v2] gc: reject if another gc is running, unless --force is given Nguyễn Thái Ngọc Duy
2013-08-03 7:52 ` Ramkumar Ramachandra
2013-08-03 10:01 ` Duy Nguyen
2013-08-03 9:49 ` Johannes Sixt
2013-08-03 10:01 ` Duy Nguyen
2013-08-03 10:40 ` Johannes Sixt
2013-08-05 14:19 ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2013-08-05 18:17 ` Junio C Hamano
2013-08-05 18:37 ` Ramkumar Ramachandra
2013-08-06 6:43 ` Junio C Hamano
2013-08-06 6:45 ` Ramkumar Ramachandra
2013-08-08 11:05 ` [PATCH v4] " Nguyễn Thái Ngọc Duy
2013-08-08 18:12 ` Junio C Hamano
2013-08-09 12:52 ` Duy Nguyen
2013-08-09 16:00 ` Junio C Hamano
2013-08-09 16:29 ` Andres Perera
2013-08-09 17:41 ` Junio C Hamano
2013-08-10 0:45 ` Duy Nguyen
2013-08-10 7:11 ` Andreas Schwab
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=1375503605-32480-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.