{"thread":{"id":"4086","subject":"[PATCH] config: if mtime (or size) of the config file changed since last read, reread it","startedAt":"2006-05-06T23:26:00Z","lastAt":"2006-05-07T08:42:10Z","messageCount":4,"participants":["Johannes Schindelin","Jan-Benedict Glaw","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19629","messageId":"Pine.LNX.4.63.0605070125010.6597@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4086","inReplyTo":null,"subject":"[PATCH] config: if mtime (or size) of the config file changed since last read, reread it","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-06T23:26:00Z","receivedAt":"2006-05-06T23:26:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tThis is extremely paranoic, I know.\n\n config.c |   16 ++++++++++------\n 1 files changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 05d4d8c..6765186 100644\n--- a/config.c\n+++ b/config.c\n@@ -13,6 +13,7 @@ #define MAXNAME (256)\n static const char *contents = NULL;\n static int config_length = 0, config_offset = 0;\n static const char *config_file_name;\n+static time_t config_file_mtime = 0;\n static int config_linenr;\n static int get_next_char(void)\n {\n@@ -255,23 +256,26 @@ int git_default_config(const char *var, \n int git_config_from_file(config_fn_t fn, const char *filename)\n {\n \tint ret, in_fd;\n+\tstruct stat st;\n \n \tconfig_offset = 0;\n \n+\tin_fd = open(filename, O_RDONLY);\n+\tfstat(in_fd, &st);\n+\n \tif (contents) {\n-\t\tif (!strcmp(config_file_name, filename))\n+\t\tif (!strcmp(config_file_name, filename)\n+\t\t\t\t&& config_file_mtime == st.st_mtime\n+\t\t\t\t&& config_length == st.st_size) {\n+\t\t\tclose(in_fd);\n \t\t\treturn git_parse_file(fn);\n+\t\t}\n \t\tmunmap((char*)contents, config_length);\n \t\tfree((char*)config_file_name);\n \t}\n \n-\tin_fd = open(filename, O_RDONLY);\n-\n \tret = -1;\n \tif (in_fd > 0) {\n-\t\tstruct stat st;\n-\n-\t\tfstat(in_fd, &st);\n \t\tconfig_length = st.st_size;\n \t\tcontents = mmap(NULL, config_length, PROT_READ, MAP_PRIVATE,\n \t\t\t\tin_fd, 0);\n-- \n1.3.1.g5545a\n"},{"id":"19630","messageId":"Pine.LNX.4.63.0605070144530.7578@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4086","inReplyTo":"Pine.LNX.4.63.0605070125010.6597@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-06T23:45:22Z","receivedAt":"2006-05-06T23:45:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nsorry: bad patch. This is needed on top.\n\ndiff --git a/config.c b/config.c\nindex 6765186..452b587 100644\n--- a/config.c\n+++ b/config.c\n@@ -261,6 +261,10 @@ int git_config_from_file(config_fn_t fn,\n \tconfig_offset = 0;\n \n \tin_fd = open(filename, O_RDONLY);\n+\tif (in_fd < 0 && ENOENT != errno )\n+\t\tdie(\"opening %s: %s\", config_file_name,\n+\t\t\t\tstrerror(errno));\n+\n \tfstat(in_fd, &st);\n \n \tif (contents) {\n@@ -288,9 +292,6 @@ int git_config_from_file(config_fn_t fn,\n \t} else {\n \t\tcontents = NULL;\n \t\tconfig_length = 0;\n-\t\tif (in_fd < 0 && ENOENT != errno )\n-\t\t\tdie(\"opening %s: %s\", config_file_name,\n-\t\t\t\t\tstrerror(errno));\n \t}\n \n \treturn ret;\n"},{"id":"19639","messageId":"20060507073052.GC17031@lug-owl.de","threadId":"4086","inReplyTo":"Pine.LNX.4.63.0605070144530.7578@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it","fromName":"Jan-Benedict Glaw","fromEmail":"jbglaw@lug-owl.de","sentAt":"2006-05-07T07:30:52Z","receivedAt":"2006-05-07T07:30:52Z","isPatch":true,"sender":{"key":"jbglaw@lug-owl.de","avatar":null},"body":"On Sun, 2006-05-07 01:45:22 +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> diff --git a/config.c b/config.c\n> index 6765186..452b587 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -261,6 +261,10 @@ int git_config_from_file(config_fn_t fn,\n>  \tconfig_offset = 0;\n>  \n>  \tin_fd = open(filename, O_RDONLY);\n> +\tif (in_fd < 0 && ENOENT != errno )\n\nI admit that I don't like the (constant -operator- variable) notation,\nbut mixing both in one line..?\n\nMfG, JBG\n\n-- \nJan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _\n\"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O\n für einen Freien Staat voll Freier Bürger\"  | im Internet! |   im Irak!   O O O\nret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));\n"},{"id":"19642","messageId":"7v8xpep6ot.fsf@assigned-by-dhcp.cox.net","threadId":"4086","inReplyTo":"20060507073052.GC17031@lug-owl.de","subject":"Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-07T08:42:10Z","receivedAt":"2006-05-07T08:42:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jan-Benedict Glaw <jbglaw@lug-owl.de> writes:\n\n>> +\tif (in_fd < 0 && ENOENT != errno )\n>\n> I admit that I don't like the (constant -operator- variable) notation,\n> but mixing both in one line..?\n\nLol.\n\nI would have written it as (in_fd < 0 && errno != ENOENT) BTW.\n"}]}