Implement git-checkout-cache -u to update stat information in the cache.
Subsystems (2)
PATCH 1/1 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 files and updates the cache. This removes the need to run git-update-cache --refresh immediately after running git-checkout-cache.
---
Documentation/git-checkout-cache.txt | 6 +++ Makefile | 2 - cache.h | 9 +++++ checkout-cache.c | 35 ++++++++++++++++++++- index.c | 58 +++++++++++++++++++++++++++++++++++ read-cache.c | 20 ++++++++++++ t/t2002-checkout-cache-u.sh | 35 +++++++++++++++++++++ update-cache.c | 48 ++-------------------------- 8 files changed, 166 insertions(+), 47 deletions(-)
index.c (. --> 100644) t/t0110-environment-names-old.sh (100644 --> 100755) t/t1000-read-tree-m-3way.sh (100644 --> 100755) t/t2002-checkout-cache-u.sh (. --> 100755) t/t4000-diff-format.sh (100644 --> 100755)
Documentation/git-checkout-cache.txt +5 -1
@@ -9,7 +9,7 @@ SYNOPSIS -------- -'git-checkout-cache' [-q] [-a] [-f] [-n] [--prefix=<string>] +'git-checkout-cache' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>] [--] <file>... DESCRIPTION
@@ -19,6 +19,10 @@ OPTIONS ------- +-u:: + update stat information for the checked out entries in + the cache file. + -q:: be quiet if files exist or are not in the cache
Makefile +1 -1
@@ -36,7 +36,7 @@ $(INSTALL) $(PROG) $(SCRIPTS) $(dest)$(bin) LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \ - tag.o date.o + tag.o date.o index.o LIB_FILE=libgit.a LIB_H=cache.h object.h blob.h tree.h commit.h tag.h
cache.h +9 -0
@@ -131,6 +131,15 @@extern int same_name (struct cache_entry *a,struct cache_entry *b);extern int cache_match_stat (struct cache_entry *ce,struct stat *st);extern int index_fd (unsigned char *sha1,int fd,struct stat *st); +extern void fill_stat_cache_info (struct cache_entry *ce,struct stat *st); + +struct cache_file { +struct cache_file *next; +char lockfile[PATH_MAX ]; +}; +extern int hold_index_file_for_update (struct cache_file *,const char *path); +extern int commit_index_file (struct cache_file *); +extern void rollback_index_file (struct cache_file *);#define MTIME_CHANGED 0x0001#define CTIME_CHANGED 0x0002
checkout-cache.c +34 -1
@@ -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 @@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 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 @@ 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 ; }
index.c +58 -0
58 lines not on this page · raw message
read-cache.c +20 -0
@@ -9,6 +9,26 @@struct cache_entry **active_cache =NULL ;unsigned int active_nr =0 , active_alloc =0 , active_cache_changed =0 ; +/* +* This only updates the "non-critical" parts of the directory +* cache, ie the parts that aren't tracked by GIT, and only used +* to validate the cache. +*/ +void fill_stat_cache_info (struct cache_entry *ce,struct stat *st) +{ + ce->ce_ctime.sec =htonl (st->st_ctime); + ce->ce_mtime.sec =htonl (st->st_mtime); +#ifdef NSEC + ce->ce_ctime.nsec =htonl (st->st_ctim.tv_nsec); + ce->ce_mtime.nsec =htonl (st->st_mtim.tv_nsec); +#endif + ce->ce_dev =htonl (st->st_dev); + ce->ce_ino =htonl (st->st_ino); + ce->ce_uid =htonl (st->st_uid); + ce->ce_gid =htonl (st->st_gid); + ce->ce_size =htonl (st->st_size); +} +int cache_match_stat (struct cache_entry *ce,struct stat *st) {unsigned int changed =0 ;
t/t2002-checkout-cache-u.sh +35 -0
@@ -0,0 +1,35 @@ +#!/bin/sh +# +# Copyright (c) 2005 Junio C Hamano +# + +test_description='git-checkout-cache -u test. + +With -u flag, git-checkout-cache internally runs the equivalent of +git-update-cache --refresh on the checked out entry.' + +. ./test-lib.sh + +test_expect_success \ +'preparation' ' +echo frotz >path0 && +git-update-cache --add path0 && +t=$(git-write-tree)' + +test_expect_failure \ +'without -u, git-checkout-cache smudges stat information.' ' +rm -f path0 && +git-read-tree $t && +git-checkout-cache -f -a && +git-diff-files | diff - /dev/null' + +test_expect_success \ +'with -u, git-checkout-cache picks up stat information from new files.' ' +rm -f path0 && +git-read-tree $t && +git-checkout-cache -u -f -a && +git-diff-files | diff - /dev/null' + + + +
update-cache.c +4 -44
82 lines not on this page · raw message
------------------------------------------------
cover Rediffed against the tip of git-pb tree
Petr, I am sending rediff against the tip of git-pb tree. One of the patches is not just rediff---the earlier version I failed to add a couple of newly created files.
[1/4] Add --author and --committer match to git-rev-list and git-rev-tree. [2/4] Tweak diff output further to make it a bit less distracting. [3/4] Implement git-checkout-cache -u to update stat information in the cache. [4/4] Trivial test harness fixes.