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:
authorEdward Thomson <ethomson@microsoft.com>2013-04-17 19:52:49 +0400
committerEdward Thomson <ethomson@microsoft.com>2013-04-17 19:52:49 +0400
commit0da62c5cf094394e7d9a4f7ef0832f8459ab3d40 (patch)
tree2349b0bbd21468e906afe781f0cacbc7f3374214 /src/checkout.c
parent1f327768c7124494ac9352e1ea5088b3678f4818 (diff)
checkout: use cache when possible to determine if workdir item is dirty
If the on-disk file has been staged (it's stat data matches the stat data in the cache) then we need not hash the file to determine whether it differs from the checkout target; instead we can simply use the oid in the index. This prevents recomputing a file's hash unnecessarily, prevents loading the file (when filtering) and prevents edge cases where filters suggest that a file is dirty immediately after git writes the file.
Diffstat (limited to 'src/checkout.c')
-rw-r--r--src/checkout.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 24fa21024..81dc5e3da 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -119,6 +119,7 @@ static bool checkout_is_workdir_modified(
const git_index_entry *wditem)
{
git_oid oid;
+ const git_index_entry *ie;
/* handle "modified" submodule */
if (wditem->mode == GIT_FILEMODE_COMMIT) {
@@ -140,6 +141,17 @@ static bool checkout_is_workdir_modified(
return (git_oid_cmp(&baseitem->oid, sm_oid) != 0);
}
+ /* Look at the cache to decide if the workdir is modified. If not,
+ * we can simply compare the oid in the cache to the baseitem instead
+ * of hashing the file.
+ */
+ if ((ie = git_index_get_bypath(data->index, wditem->path, 0)) != NULL) {
+ if (wditem->mtime.seconds == ie->mtime.seconds &&
+ wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
+ wditem->file_size == ie->file_size)
+ return (git_oid_cmp(&baseitem->oid, &ie->oid) != 0);
+ }
+
/* depending on where base is coming from, we may or may not know
* the actual size of the data, so we can't rely on this shortcut.
*/