aboutsummaryrefslogtreecommitdiff
path: root/checkout-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-05-15 14:23:12 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-19 09:50:57 -0700
commit415e96c8b7e7d47f98a45ae1b6d524418245a3b4 (patch)
tree08f5f8433a6d56642b64fe9ab941647da6c8aef5 /checkout-cache.c
parent875d0f8ddb1d420f6465498842740c4f5ab03e6f (diff)
downloadgit-415e96c8b7e7d47f98a45ae1b6d524418245a3b4.tar.gz
git-415e96c8b7e7d47f98a45ae1b6d524418245a3b4.tar.xz
[PATCH] Implement git-checkout-cache -u to update stat information in the cache.
With -u flag, git-checkout-cache picks up the stat information from newly created file and updates the cache. This removes the need to run git-update-cache --refresh immediately after running git-checkout-cache. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'checkout-cache.c')
-rw-r--r--checkout-cache.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/checkout-cache.c b/checkout-cache.c
index 462aea55a..bc486ba07 100644
--- a/checkout-cache.c
+++ b/checkout-cache.c
@@ -36,7 +36,7 @@
#include <dirent.h>
#include "cache.h"
-static int force = 0, quiet = 0, not_new = 0;
+static int force = 0, quiet = 0, not_new = 0, refresh_cache = 0;
static void create_directories(const char *path)
{
@@ -154,6 +154,12 @@ static int write_entry(struct cache_entry *ce, const char *path)
free(new);
return error("checkout-cache: unknown file mode for %s", path);
}
+
+ if (refresh_cache) {
+ struct stat st;
+ lstat(ce->name, &st);
+ fill_stat_cache_info(ce, &st);
+ }
return 0;
}
@@ -224,6 +230,8 @@ int main(int argc, char **argv)
{
int i, force_filename = 0;
const char *base_dir = "";
+ struct cache_file cache_file;
+ int newfd = -1;
if (read_cache() < 0) {
die("invalid cache");
@@ -252,12 +260,37 @@ int main(int argc, char **argv)
not_new = 1;
continue;
}
+ if (!strcmp(arg, "-u")) {
+ refresh_cache = 1;
+ if (newfd < 0)
+ newfd = hold_index_file_for_update
+ (&cache_file,
+ get_index_file());
+ if (newfd < 0)
+ die("cannot open index.lock file.");
+ continue;
+ }
if (!memcmp(arg, "--prefix=", 9)) {
base_dir = arg+9;
continue;
}
}
+ if (base_dir[0]) {
+ /* when --prefix is specified we do not
+ * want to update cache.
+ */
+ if (refresh_cache) {
+ close(newfd); newfd = -1;
+ rollback_index_file(&cache_file);
+ }
+ refresh_cache = 0;
+ }
checkout_file(arg, base_dir);
}
+
+ if (0 <= newfd &&
+ (write_cache(newfd, active_cache, active_nr) ||
+ commit_index_file(&cache_file)))
+ die("Unable to write new cachefile");
return 0;
}