git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Run git status in the background.
@ 2013-03-21 12:29 Fredrik Gustafsson
  2013-03-25  9:12 ` Ramkumar Ramachandra
  0 siblings, 1 reply; 2+ messages in thread
From: Fredrik Gustafsson @ 2013-03-21 12:29 UTC (permalink / raw)
  To: spearce; +Cc: artagnon, git, peff, pclouds, iveqy

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-25  9:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-21 12:29 [PATCH] Run git status in the background Fredrik Gustafsson
2013-03-25  9:12 ` Ramkumar Ramachandra

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).