{"thread":{"id":"33245","subject":"[PATCH] Run git status in the background.","startedAt":"2013-03-21T12:29:28Z","lastAt":"2013-03-25T09:12:29Z","messageCount":2,"participants":["Fredrik Gustafsson","Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"211856","messageId":"1363868968-19553-1-git-send-email-iveqy@iveqy.com","threadId":"33245","inReplyTo":null,"subject":"[PATCH] Run git status in the background.","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-03-21T12:29:28Z","receivedAt":"2013-03-21T12:29:28Z","isPatch":true,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"If core.preload is set to a non-zero value, every time a git command is\nexecuted, git status will be runned in the background if the value of\ncore.preload is lower than the number of seconds since last run.\n\nPlease see this thread:\nhttp://article.gmane.org/gmane.comp.version-control.git/218587\n\nThis solution solves many of the problems discussed there, but\nintroduces new ones. For example, it does have a bigger impact.\n\nWith this solution beeing functional but a bit gross, it's not sure that\nit should be placed here at all. However, it's a good place to place it\nfor all git-tools to be able to use it without knowing about it. (It\nwould speed up all git wrappers and not just bash-prompt like the\nprevious solution).\n\nThere's a few more things to address before shipping this if this is\nconsidered a good approach. Such as:\n\t* Don't run if a \"git status\"-like git command has been runned. Or a\n\t  non-repo git command (lite git status or git help) is runned.\n\t* Better names for settings and files.\n\t* Better(?) invokation of git status (a forked internal call instead\n\t  of a system call?).\n\nSigned-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n---\n git.c | 30 ++++++++++++++++++++++++++++++\n 1 file changed, 30 insertions(+)\n\ndiff --git a/git.c b/git.c\nindex 39ba6b1..829aa9c 100644\n--- a/git.c\n+++ b/git.c\n@@ -231,6 +231,14 @@ static int handle_alias(int *argcp, const char ***argv)\n \treturn ret;\n }\n \n+static int preload_rate = 0;\n+static int preload_cb(const char *k, const char *v, void *cb)\n+{\n+\tif (strcmp(k, \"core.preload\") == 0)\n+\t\tpreload_rate = git_config_int(k, v);\n+\treturn 0;\n+}\n+\n #define RUN_SETUP\t\t(1<<0)\n #define RUN_SETUP_GENTLY\t(1<<1)\n #define USE_PAGER\t\t(1<<2)\n@@ -278,6 +286,28 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \ttrace_argv_printf(argv, \"trace: built-in: git\");\n \n+\t/* Check if we shall run git status in the background */\n+\tgit_config(preload_cb, NULL);\n+\tif (preload_rate > 0) {\n+\t\tconst char * git_dir = get_git_dir();\n+\t\tchar lastrun[512];\n+\t\tstrcpy(lastrun, git_dir);\n+\t\tstrcat(lastrun, \"/lastrun\");\n+\n+\t\tstruct stat * lr = malloc(sizeof(struct stat));\n+\t\tstat(lastrun, lr);\n+\n+\t\tif ((time(NULL) - lr->st_mtime) > preload_rate) {\n+\t\t\tsystem(\"git status > /dev/null 2>&1 &\");\n+\t\t\tprintf(\"RUN\\n\");\n+\t\t}\n+\n+\t\t// This should be done for a few other commands as well.\n+\t\t// So that we don't spawn git-status if the user just runned that command.\n+\t\tFILE * touch = fopen(lastrun, \"w\");\n+\t\tfclose(touch);\n+\t}\n+\n \tstatus = p->fn(argc, argv, prefix);\n \tif (status)\n \t\treturn status;\n-- \n1.8.1.5\n"},{"id":"212153","messageId":"CALkWK0magR+9BsFRZYYmNAXTvV8Y-6reLOC1YCUm2fCBRrzFNA@mail.gmail.com","threadId":"33245","inReplyTo":"1363868968-19553-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH] Run git status in the background.","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-03-25T09:12:29Z","receivedAt":"2013-03-25T09:12:29Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Fredrik Gustafsson wrote:\n> If core.preload is set to a non-zero value, every time a git command is\n> executed, git status will be runned in the background if the value of\n> core.preload is lower than the number of seconds since last run.\n\nCounting the number of seconds since the last run is gross.  This kind\nof setting makes sense in the credential-helper, where you specify how\nlong to cache your password.  I don't think you should use a\ntime-based trigger for this feature.\n\n> Please see this thread:\n> http://article.gmane.org/gmane.comp.version-control.git/218587\n>\n> This solution solves many of the problems discussed there, but\n> introduces new ones. For example, it does have a bigger impact.\n>\n> With this solution beeing functional but a bit gross, it's not sure that\n> it should be placed here at all. However, it's a good place to place it\n> for all git-tools to be able to use it without knowing about it. (It\n> would speed up all git wrappers and not just bash-prompt like the\n> previous solution).\n\nYes, but you're proposing including a very gross feature in core git.\nI'm sorry, but this is a non-starter.\n\n> There's a few more things to address before shipping this if this is\n> considered a good approach. Such as:\n>         * Don't run if a \"git status\"-like git command has been runned. Or a\n>           non-repo git command (lite git status or git help) is runned.\n>         * Better names for settings and files.\n>         * Better(?) invokation of git status (a forked internal call instead\n>           of a system call?).\n>\n> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n> ---\n>  git.c | 30 ++++++++++++++++++++++++++++++\n>  1 file changed, 30 insertions(+)\n\nI would argue that git.c is the wrong place to implement this feature.\n You're essentially doing fopen(), fclose(), stat(), and system():\nshouldn't this be a shell script?  I earlier suggested making it\nsomething we can hook to chpwd() in zsh, and I think this is the most\nsane suggestion.  This is what z() [1] uses, and I would argue that\nyour feature shares many similarities with it.\n\n[1]: https://github.com/rupa/z\n"}]}