* [PATCH] config: if mtime (or size) of the config file changed since last read, reread it
@ 2006-05-06 23:26 Johannes Schindelin
2006-05-06 23:45 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2006-05-06 23:26 UTC (permalink / raw)
To: git
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it
2006-05-06 23:26 [PATCH] config: if mtime (or size) of the config file changed since last read, reread it Johannes Schindelin
@ 2006-05-06 23:45 ` Johannes Schindelin
2006-05-07 7:30 ` Jan-Benedict Glaw
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2006-05-06 23:45 UTC (permalink / raw)
To: git
Hi,
sorry: bad patch. This is needed on top.
diff --git a/config.c b/config.c
index 6765186..452b587 100644
--- a/config.c
+++ b/config.c
@@ -261,6 +261,10 @@ int git_config_from_file(config_fn_t fn,
config_offset = 0;
in_fd = open(filename, O_RDONLY);
+ if (in_fd < 0 && ENOENT != errno )
+ die("opening %s: %s", config_file_name,
+ strerror(errno));
+
fstat(in_fd, &st);
if (contents) {
@@ -288,9 +292,6 @@ int git_config_from_file(config_fn_t fn,
} else {
contents = NULL;
config_length = 0;
- if (in_fd < 0 && ENOENT != errno )
- die("opening %s: %s", config_file_name,
- strerror(errno));
}
return ret;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it
2006-05-06 23:45 ` Johannes Schindelin
@ 2006-05-07 7:30 ` Jan-Benedict Glaw
2006-05-07 8:42 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Jan-Benedict Glaw @ 2006-05-07 7:30 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 820 bytes --]
On Sun, 2006-05-07 01:45:22 +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> diff --git a/config.c b/config.c
> index 6765186..452b587 100644
> --- a/config.c
> +++ b/config.c
> @@ -261,6 +261,10 @@ int git_config_from_file(config_fn_t fn,
> config_offset = 0;
>
> in_fd = open(filename, O_RDONLY);
> + if (in_fd < 0 && ENOENT != errno )
I admit that I don't like the (constant -operator- variable) notation,
but mixing both in one line..?
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
für einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] config: if mtime (or size) of the config file changed since last read, reread it
2006-05-07 7:30 ` Jan-Benedict Glaw
@ 2006-05-07 8:42 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2006-05-07 8:42 UTC (permalink / raw)
To: Jan-Benedict Glaw; +Cc: git
Jan-Benedict Glaw <jbglaw@lug-owl.de> writes:
>> + if (in_fd < 0 && ENOENT != errno )
>
> I admit that I don't like the (constant -operator- variable) notation,
> but mixing both in one line..?
Lol.
I would have written it as (in_fd < 0 && errno != ENOENT) BTW.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-05-07 8:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-06 23:26 [PATCH] config: if mtime (or size) of the config file changed since last read, reread it Johannes Schindelin
2006-05-06 23:45 ` Johannes Schindelin
2006-05-07 7:30 ` Jan-Benedict Glaw
2006-05-07 8:42 ` Junio C Hamano
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).