Commit c8b511f3 by Russell Belfer

Better naming for file timestamp/size checker

parent 744cc03e
...@@ -261,13 +261,13 @@ bool git_attr_cache__is_cached( ...@@ -261,13 +261,13 @@ bool git_attr_cache__is_cached(
static int load_attr_file( static int load_attr_file(
const char **data, const char **data,
git_futils_stat_sig *sig, git_futils_file_stamp *stamp,
const char *filename) const char *filename)
{ {
int error; int error;
git_buf content = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT;
error = git_futils_stat_sig_needs_reload(sig, filename); error = git_futils_file_stamp_has_changed(stamp, filename);
if (error < 0) if (error < 0)
return error; return error;
...@@ -380,7 +380,7 @@ int git_attr_cache__push_file( ...@@ -380,7 +380,7 @@ int git_attr_cache__push_file(
git_attr_cache *cache = git_repository_attr_cache(repo); git_attr_cache *cache = git_repository_attr_cache(repo);
git_attr_file *file = NULL; git_attr_file *file = NULL;
git_blob *blob = NULL; git_blob *blob = NULL;
git_futils_stat_sig sig; git_futils_file_stamp stamp;
assert(filename && stack); assert(filename && stack);
...@@ -402,12 +402,10 @@ int git_attr_cache__push_file( ...@@ -402,12 +402,10 @@ int git_attr_cache__push_file(
/* if not in cache, load data, parse, and cache */ /* if not in cache, load data, parse, and cache */
if (source == GIT_ATTR_FILE_FROM_FILE) { if (source == GIT_ATTR_FILE_FROM_FILE) {
if (file) git_futils_file_stamp_set(
memcpy(&sig, &file->cache_data.sig, sizeof(sig)); &stamp, file ? &file->cache_data.stamp : NULL);
else
memset(&sig, 0, sizeof(sig));
error = load_attr_file(&content, &sig, filename); error = load_attr_file(&content, &stamp, filename);
} else { } else {
error = load_attr_blob_from_index(&content, &blob, error = load_attr_blob_from_index(&content, &blob,
repo, file ? &file->cache_data.oid : NULL, relfile); repo, file ? &file->cache_data.oid : NULL, relfile);
...@@ -442,7 +440,7 @@ int git_attr_cache__push_file( ...@@ -442,7 +440,7 @@ int git_attr_cache__push_file(
if (blob) if (blob)
git_oid_cpy(&file->cache_data.oid, git_object_id((git_object *)blob)); git_oid_cpy(&file->cache_data.oid, git_object_id((git_object *)blob));
else else
memcpy(&file->cache_data.sig, &sig, sizeof(sig)); git_futils_file_stamp_set(&file->cache_data.stamp, &stamp);
finish: finish:
/* push file onto vector if we found one*/ /* push file onto vector if we found one*/
......
...@@ -61,7 +61,7 @@ typedef struct { ...@@ -61,7 +61,7 @@ typedef struct {
bool pool_is_allocated; bool pool_is_allocated;
union { union {
git_oid oid; git_oid oid;
git_futils_stat_sig sig; git_futils_file_stamp stamp;
} cache_data; } cache_data;
} git_attr_file; } git_attr_file;
......
...@@ -671,27 +671,37 @@ int git_futils_cp_r( ...@@ -671,27 +671,37 @@ int git_futils_cp_r(
return error; return error;
} }
int git_futils_stat_sig_needs_reload( int git_futils_file_stamp_has_changed(
git_futils_stat_sig *sig, const char *path) git_futils_file_stamp *stamp, const char *path)
{ {
struct stat st; struct stat st;
/* if the sig is NULL, then alway reload */ /* if the stamp is NULL, then always reload */
if (sig == NULL) if (stamp == NULL)
return 1; return 1;
if (p_stat(path, &st) < 0) if (p_stat(path, &st) < 0)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
if ((git_time_t)st.st_mtime == sig->seconds && if (stamp->mtime == (git_time_t)st.st_mtime &&
(git_off_t)st.st_size == sig->size && stamp->size == (git_off_t)st.st_size &&
(unsigned int)st.st_ino == sig->ino) stamp->ino == (unsigned int)st.st_ino)
return 0; return 0;
sig->seconds = (git_time_t)st.st_mtime; stamp->mtime = (git_time_t)st.st_mtime;
sig->size = (git_off_t)st.st_size; stamp->size = (git_off_t)st.st_size;
sig->ino = (unsigned int)st.st_ino; stamp->ino = (unsigned int)st.st_ino;
return 1; return 1;
} }
void git_futils_file_stamp_set(
git_futils_file_stamp *target, const git_futils_file_stamp *source)
{
assert(target);
if (source)
memcpy(target, source, sizeof(*target));
else
memset(target, 0, sizeof(*target));
}
...@@ -267,26 +267,44 @@ extern int git_futils_find_system_file(git_buf *path, const char *filename); ...@@ -267,26 +267,44 @@ extern int git_futils_find_system_file(git_buf *path, const char *filename);
*/ */
extern int git_futils_fake_symlink(const char *new, const char *old); extern int git_futils_fake_symlink(const char *new, const char *old);
/**
* A file stamp represents a snapshot of information about a file that can
* be used to test if the file changes. This portable implementation is
* based on stat data about that file, but it is possible that OS specific
* versions could be implemented in the future.
*/
typedef struct { typedef struct {
git_time_t seconds; git_time_t mtime;
git_off_t size; git_off_t size;
unsigned int ino; unsigned int ino;
} git_futils_stat_sig; } git_futils_file_stamp;
/** /**
* Compare stat information for file with reference info. * Compare stat information for file with reference info.
* *
* Use this as a way to track if a file has changed on disk. This will * This function updates the file stamp to current data for the given path
* return GIT_ENOTFOUND if the file doesn't exist, 0 if the file is up-to-date * and returns 0 if the file is up-to-date relative to the prior setting or
* with regards to the signature, and 1 if the file needs to reloaded. When * 1 if the file has been changed. (This also may return GIT_ENOTFOUND if
* a 1 is returned, the signature will also be updated with the latest data. * the file doesn't exist.)
* *
* @param sig stat signature structure * @param stamp File stamp to be checked
* @param path path to be statted * @param path Path to stat and check if changed
* @return 0 if up-to-date, 1 if out-of-date, <0 on error * @return 0 if up-to-date, 1 if out-of-date, <0 on error
*/ */
extern int git_futils_stat_sig_needs_reload( extern int git_futils_file_stamp_has_changed(
git_futils_stat_sig *sig, const char *path); git_futils_file_stamp *stamp, const char *path);
/**
* Set or reset file stamp data
*
* This writes the target file stamp. If the source is NULL, this will set
* the target stamp to values that will definitely be out of date. If the
* source is not NULL, this copies the source values to the target.
*
* @param tgt File stamp to write to
* @param src File stamp to copy from or NULL to clear the target
*/
extern void git_futils_file_stamp_set(
git_futils_file_stamp *tgt, const git_futils_file_stamp *src);
#endif /* INCLUDE_fileops_h__ */ #endif /* INCLUDE_fileops_h__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment