diff options
| author | Russell Belfer <rb@github.com> | 2013-06-27 16:52:38 -0700 | 
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-07-10 12:14:13 -0700 | 
| commit | e807860fa9b5278932a0ba25f84b4035b0ebda84 (patch) | |
| tree | e964313861cb1dbf3fb79a0d9617e54d16edd807 /src/submodule.c | |
| parent | 41f1f9d732a7cdd50d58948224ca0693a68995dc (diff) | |
| download | libgit2-e807860fa9b5278932a0ba25f84b4035b0ebda84.tar.gz | |
Add timestamp check to submodule status
This is probably not the final form of this change, but this is
a preliminary version of checking a timestamp to see if the cached
working directory HEAD OID matches the current.  Right now, this
uses the timestamp on the index and is, like most of our timestamp
checking, subject to having only second accuracy.
Diffstat (limited to 'src/submodule.c')
| -rw-r--r-- | src/submodule.c | 42 | 
1 files changed, 37 insertions, 5 deletions
diff --git a/src/submodule.c b/src/submodule.c index dcd58d016..e6ed7e33e 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -9,9 +9,7 @@  #include "git2/config.h"  #include "git2/sys/config.h"  #include "git2/types.h" -#include "git2/repository.h"  #include "git2/index.h" -#include "git2/submodule.h"  #include "buffer.h"  #include "buf_text.h"  #include "vector.h" @@ -544,6 +542,15 @@ const git_oid *git_submodule_wd_id(git_submodule *submodule)  {  	assert(submodule); +	/* if we know the submodule index timestamp and it has moved, then +	 * let's reload the working directory information for the submodule +	 */ +	if (submodule->wd_head_path != NULL && +		git_futils_filestamp_check( +			&submodule->wd_stamp, submodule->wd_head_path)) +		submodule->flags &= ~GIT_SUBMODULE_STATUS__WD_OID_VALID; + +	/* load unless we think we have a valid oid */  	if (!(submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID)) {  		git_repository *subrepo; @@ -702,11 +709,36 @@ int git_submodule_open(  	/* if we have opened the submodule successfully, let's grab the HEAD OID */  	if (!error) { +		git_buf buf = GIT_BUF_INIT; + +		/* For now, let's just the index timestamp... +		 * +		 * git_buf_joinpath(&buf, git_repository_path(*subrepo), GIT_HEAD_FILE); +		 * if (!git_path_exists(buf.ptr)) { +		 */ +			git_index *index; +			if (!git_repository_index__weakptr(&index, *subrepo)) +				git_buf_sets(&buf, git_index_path(index)); +			else +				git_buf_free(&buf); +		/* } */ + +		if (git_buf_len(&buf) > 0) { +			git__free(submodule->wd_head_path); +			submodule->wd_head_path = git_buf_detach(&buf); +		} +  		if (!git_reference_name_to_id( -				&submodule->wd_oid, *subrepo, GIT_HEAD_FILE)) +				&submodule->wd_oid, *subrepo, GIT_HEAD_FILE)) { +  			submodule->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID; -		else -			giterr_clear(); + +			if (submodule->wd_head_path) +				git_futils_filestamp_check( +					&submodule->wd_stamp, submodule->wd_head_path); +		} + +		giterr_clear();  	}  	return error;  | 
