git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fredrik Gustafsson <iveqy@iveqy.com>
To: spearce@spearce.org
Cc: artagnon@gmail.com, git@vger.kernel.org, peff@peff.net,
	pclouds@gmail.com, iveqy@iveqy.com
Subject: [PATCH] Run git status in the background.
Date: Thu, 21 Mar 2013 13:29:28 +0100	[thread overview]
Message-ID: <1363868968-19553-1-git-send-email-iveqy@iveqy.com> (raw)

If core.preload is set to a non-zero value, every time a git command is
executed, git status will be runned in the background if the value of
core.preload is lower than the number of seconds since last run.

Please see this thread:
http://article.gmane.org/gmane.comp.version-control.git/218587

This solution solves many of the problems discussed there, but
introduces new ones. For example, it does have a bigger impact.

With this solution beeing functional but a bit gross, it's not sure that
it should be placed here at all. However, it's a good place to place it
for all git-tools to be able to use it without knowing about it. (It
would speed up all git wrappers and not just bash-prompt like the
previous solution).

There's a few more things to address before shipping this if this is
considered a good approach. Such as:
	* Don't run if a "git status"-like git command has been runned. Or a
	  non-repo git command (lite git status or git help) is runned.
	* Better names for settings and files.
	* Better(?) invokation of git status (a forked internal call instead
	  of a system call?).

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
 git.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/git.c b/git.c
index 39ba6b1..829aa9c 100644
--- a/git.c
+++ b/git.c
@@ -231,6 +231,14 @@ static int handle_alias(int *argcp, const char ***argv)
 	return ret;
 }
 
+static int preload_rate = 0;
+static int preload_cb(const char *k, const char *v, void *cb)
+{
+	if (strcmp(k, "core.preload") == 0)
+		preload_rate = git_config_int(k, v);
+	return 0;
+}
+
 #define RUN_SETUP		(1<<0)
 #define RUN_SETUP_GENTLY	(1<<1)
 #define USE_PAGER		(1<<2)
@@ -278,6 +286,28 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
 	trace_argv_printf(argv, "trace: built-in: git");
 
+	/* Check if we shall run git status in the background */
+	git_config(preload_cb, NULL);
+	if (preload_rate > 0) {
+		const char * git_dir = get_git_dir();
+		char lastrun[512];
+		strcpy(lastrun, git_dir);
+		strcat(lastrun, "/lastrun");
+
+		struct stat * lr = malloc(sizeof(struct stat));
+		stat(lastrun, lr);
+
+		if ((time(NULL) - lr->st_mtime) > preload_rate) {
+			system("git status > /dev/null 2>&1 &");
+			printf("RUN\n");
+		}
+
+		// This should be done for a few other commands as well.
+		// So that we don't spawn git-status if the user just runned that command.
+		FILE * touch = fopen(lastrun, "w");
+		fclose(touch);
+	}
+
 	status = p->fn(argc, argv, prefix);
 	if (status)
 		return status;
-- 
1.8.1.5

             reply	other threads:[~2013-03-21 12:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21 12:29 Fredrik Gustafsson [this message]
2013-03-25  9:12 ` [PATCH] Run git status in the background Ramkumar Ramachandra

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=1363868968-19553-1-git-send-email-iveqy@iveqy.com \
    --to=iveqy@iveqy.com \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=spearce@spearce.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 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).