Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-10-30 23:10:36 +0400
committerRussell Belfer <rb@github.com>2012-10-30 23:11:23 +0400
commit744cc03e2b6d77712bfcb504c272d2e646da650c (patch)
tree6dd5c8cf23e02cf4a5b96800e19dc9749d08cc75 /src/attr.c
parentefde422553e1181933d0bc9d7112740e858a847b (diff)
Add git_config_refresh() API to reload config
This adds a new API that allows users to reload the config if the file has changed on disk. A new config callback function to refresh the config was added. The modified time and file size are used to test if the file needs to be reloaded (and are now stored in the disk backend object). In writing tests, just using mtime was a problem / race, so I wanted to check file size as well. To support that, I extended `git_futils_readbuffer_updated` to optionally check file size in addition to mtime, and I added a new function `git_filebuf_stats` to fetch the mtime and size for an open filebuf (so that the config could be easily refreshed after a write). Lastly, I moved some similar file checking code for attributes into filebuf. It is still only being used for attrs, but it seems potentially reusable, so I thought I'd move it over.
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/attr.c b/src/attr.c
index f5e09cc08..50caa1e1b 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -261,32 +261,26 @@ bool git_attr_cache__is_cached(
static int load_attr_file(
const char **data,
- git_attr_file_stat_sig *sig,
+ git_futils_stat_sig *sig,
const char *filename)
{
int error;
git_buf content = GIT_BUF_INIT;
- struct stat st;
- if (p_stat(filename, &st) < 0)
- return GIT_ENOTFOUND;
+ error = git_futils_stat_sig_needs_reload(sig, filename);
+ if (error < 0)
+ return error;
- if (sig != NULL &&
- (git_time_t)st.st_mtime == sig->seconds &&
- (git_off_t)st.st_size == sig->size &&
- (unsigned int)st.st_ino == sig->ino)
+ /* if error == 0, then file is up to date. By returning GIT_ENOTFOUND,
+ * we tell the caller not to reparse this file...
+ */
+ if (!error)
return GIT_ENOTFOUND;
- error = git_futils_readbuffer_updated(&content, filename, NULL, NULL);
+ error = git_futils_readbuffer(&content, filename);
if (error < 0)
return error;
- if (sig != NULL) {
- sig->seconds = (git_time_t)st.st_mtime;
- sig->size = (git_off_t)st.st_size;
- sig->ino = (unsigned int)st.st_ino;
- }
-
*data = git_buf_detach(&content);
return 0;
@@ -386,7 +380,7 @@ int git_attr_cache__push_file(
git_attr_cache *cache = git_repository_attr_cache(repo);
git_attr_file *file = NULL;
git_blob *blob = NULL;
- git_attr_file_stat_sig st;
+ git_futils_stat_sig sig;
assert(filename && stack);
@@ -409,11 +403,11 @@ int git_attr_cache__push_file(
if (source == GIT_ATTR_FILE_FROM_FILE) {
if (file)
- memcpy(&st, &file->cache_data.st, sizeof(st));
+ memcpy(&sig, &file->cache_data.sig, sizeof(sig));
else
- memset(&st, 0, sizeof(st));
+ memset(&sig, 0, sizeof(sig));
- error = load_attr_file(&content, &st, filename);
+ error = load_attr_file(&content, &sig, filename);
} else {
error = load_attr_blob_from_index(&content, &blob,
repo, file ? &file->cache_data.oid : NULL, relfile);
@@ -448,7 +442,7 @@ int git_attr_cache__push_file(
if (blob)
git_oid_cpy(&file->cache_data.oid, git_object_id((git_object *)blob));
else
- memcpy(&file->cache_data.st, &st, sizeof(st));
+ memcpy(&file->cache_data.sig, &sig, sizeof(sig));
finish:
/* push file onto vector if we found one*/