git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Run git status in the background.

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Mar 21, 2013, 12:29 UTC
Message-ID
<1363868968-19553-1-git-send-email-iveqy@iveqy.com>

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
Next: Ramkumar Ramachandra
Message 1 of 2 in “Run git status in the background.”
  1. Run git status in the background.Fredrik Gustafsson, Mar 21, 2013
  2. Ramkumar RamachandraMar 25, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.