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

[PATCH] config: if mtime (or size) of the config file changed since last read, reread it

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 6, 2006, 23:26 UTC
Message-ID
<Pine.LNX.4.63.0605070125010.6597@wbgn013.biozentrum.uni-wuerzburg.de>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	This is extremely paranoic, I know.
 config.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/config.c b/config.c
index 05d4d8c..6765186 100644
--- a/config.c
+++ b/config.c
@@ -13,6 +13,7 @@ #define MAXNAME (256)
 static const char *contents = NULL;
 static int config_length = 0, config_offset = 0;
 static const char *config_file_name;
+static time_t config_file_mtime = 0;
 static int config_linenr;
 static int get_next_char(void)
 {
@@ -255,23 +256,26 @@ int git_default_config(const char *var, 
 int git_config_from_file(config_fn_t fn, const char *filename)
 {
 	int ret, in_fd;
+	struct stat st;
 
 	config_offset = 0;
 
+	in_fd = open(filename, O_RDONLY);
+	fstat(in_fd, &st);
+
 	if (contents) {
-		if (!strcmp(config_file_name, filename))
+		if (!strcmp(config_file_name, filename)
+				&& config_file_mtime == st.st_mtime
+				&& config_length == st.st_size) {
+			close(in_fd);
 			return git_parse_file(fn);
+		}
 		munmap((char*)contents, config_length);
 		free((char*)config_file_name);
 	}
 
-	in_fd = open(filename, O_RDONLY);
-
 	ret = -1;
 	if (in_fd > 0) {
-		struct stat st;
-
-		fstat(in_fd, &st);
 		config_length = st.st_size;
 		contents = mmap(NULL, config_length, PROT_READ, MAP_PRIVATE,
 				in_fd, 0);
-- 
1.3.1.g5545a
Next: Johannes Schindelin
Message 1 of 4 in “config: if mtime (or size) of the config file changed since last read, reread it”
  1. config: if mtime (or size) of the config file changed since last read, reread itJohannes Schindelin, May 6, 2006
  2. Johannes SchindelinMay 6, 2006
  3. Jan-Benedict GlawMay 7, 2006
  4. Junio C HamanoMay 7, 2006

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.