git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [RFC PATCH] gc --auto: don't lie about running in background on Windows
Date: Thu,  5 May 2016 17:16:46 +0200	[thread overview]
Message-ID: <20160505151646.13189-1-szeder@ira.uka.de> (raw)
In-Reply-To: <20160505171430.Horde.-GuvDpZBfS8VI1Zcfn4bJQI@webmail.informatik.kit.edu>

When 'git gc --auto' is invoked it tells the user whether it is about
to auto pack the repository in the background or in the foreground
depending on 'gc.autoDetach' (enabled by default).  However, going to
the background is not supported at all on Windows, yet 'git gc --auto'
by default claims that it will do so.

Add a helper function that can tell whether the platform supports
going to the background and use it in the 'git gc --auto' codepath to
print an honest message.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

I built and tested with 'NO_POSIX_GOODIES=UnfortunatelyYes': it
worked.  However, I did not test it on Windows due to lack of
resources, hence the RFC out of caution.

Arguably this helper function could be just a simple variable.  I
opted for a function because:

  - I preferred a single '#ifdef NO_POSIX_GOODIES', and putting a
    static variable so near to EOF felt just wrong.  (And this is why
    it's not an inline-able function defined in a header file.)

  - currently we know already at compile time that Windows can't
    daemonize, but in the future we might want to extend this helper
    function to perform some runtime checks, too.  But this is perhaps
    like preparing for crossing a bridge where we'll never get to.

 builtin/gc.c |  1 +
 cache.h      |  1 +
 setup.c      | 17 +++++++++++++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index c583aad6ec28..79a0f6dc1126 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -368,6 +368,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		 */
 		if (!need_to_gc())
 			return 0;
+		detach_auto &= can_daemonize();
 		if (!quiet) {
 			if (detach_auto)
 				fprintf(stderr, _("Auto packing the repository in background for optimum performance.\n"));
diff --git a/cache.h b/cache.h
index fd728f079320..3662e5aabb98 100644
--- a/cache.h
+++ b/cache.h
@@ -524,6 +524,7 @@ extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int);
 extern int init_db(const char *template_dir, unsigned int flags);
 
 extern void sanitize_stdfds(void);
+extern int can_daemonize(void);
 extern int daemonize(void);
 
 #define alloc_nr(x) (((x)+16)*3/2)
diff --git a/setup.c b/setup.c
index c86bf5c9fabe..6187a4ad9c47 100644
--- a/setup.c
+++ b/setup.c
@@ -1033,12 +1033,25 @@ void sanitize_stdfds(void)
 		close(fd);
 }
 
+#ifdef NO_POSIX_GOODIES
+int can_daemonize(void)
+{
+	return 0;
+}
+
 int daemonize(void)
 {
-#ifdef NO_POSIX_GOODIES
 	errno = ENOSYS;
 	return -1;
+}
 #else
+int can_daemonize(void)
+{
+	return 1;
+}
+
+int daemonize(void)
+{
 	switch (fork()) {
 		case 0:
 			break;
@@ -1054,5 +1067,5 @@ int daemonize(void)
 	close(2);
 	sanitize_stdfds();
 	return 0;
-#endif
 }
+#endif /* #ifdef NO_POSIX_GOODIES */
-- 
2.8.2.356.ge684b1d

  reply	other threads:[~2016-05-05 15:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-01 15:37 [PATCH] t5510: run auto-gc in the foreground SZEDER Gábor
2016-05-02  7:01 ` Johannes Schindelin
2016-05-02 23:55   ` SZEDER Gábor
2016-05-03 11:50     ` SZEDER Gábor
2016-05-04  5:48       ` Johannes Schindelin
2016-05-05 15:14         ` SZEDER Gábor
2016-05-05 15:16           ` SZEDER Gábor [this message]
2016-05-05 16:28             ` [RFC PATCH] gc --auto: don't lie about running in background on Windows Junio C Hamano
2016-05-07 14:44               ` SZEDER Gábor

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=20160505151646.13189-1-szeder@ira.uka.de \
    --to=szeder@ira.uka.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).