Skip to content

Commit a9bfe81

Browse files
committed
Merge branch 'kb/checkout-optim'
* kb/checkout-optim: Revert "lstat_cache(): print a warning if doing ping-pong between cache types" checkout bugfix: use stat.mtime instead of stat.ctime in two places Makefile: Set compiler switch for USE_NSEC Create USE_ST_TIMESPEC and turn it on for Darwin Not all systems use st_[cm]tim field for ns resolution file timestamp Record ns-timestamps if possible, but do not use it without USE_NSEC write_index(): update index_state->timestamp after flushing to disk verify_uptodate(): add ce_uptodate(ce) test make USE_NSEC work as expected fix compile error when USE_NSEC is defined check_updates(): effective removal of cache entries marked CE_REMOVE lstat_cache(): print a warning if doing ping-pong between cache types show_patch_diff(): remove a call to fstat() write_entry(): use fstat() instead of lstat() when file is open write_entry(): cleanup of some duplicated code create_directories(): remove some memcpy() and strchr() calls unlink_entry(): introduce schedule_dir_for_removal() lstat_cache(): swap func(length, string) into func(string, length) lstat_cache(): generalise longest_match_lstat_cache() lstat_cache(): small cleanup and optimisation
2 parents 642d084 + 381b920 commit a9bfe81

File tree

15 files changed

+296
-170
lines changed

15 files changed

+296
-170
lines changed

Documentation/CodingGuidelines

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ For C programs:
129129
used in the git core command set (unless your command is clearly
130130
separate from it, such as an importer to convert random-scm-X
131131
repositories to git).
132+
133+
- When we pass <string, length> pair to functions, we should try to
134+
pass them in that order.

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ all::
126126
# randomly break unless your underlying filesystem supports those sub-second
127127
# times (my ext3 doesn't).
128128
#
129+
# Define USE_ST_TIMESPEC if your "struct stat" uses "st_ctimespec" instead of
130+
# "st_ctim"
131+
#
132+
# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
133+
# available. This automatically turns USE_NSEC off.
134+
#
129135
# Define USE_STDEV below if you want git to care about the underlying device
130136
# change being considered an inode change from the update-index perspective.
131137
#
@@ -657,6 +663,7 @@ ifeq ($(uname_S),Darwin)
657663
endif
658664
NO_MEMMEM = YesPlease
659665
THREADED_DELTA_SEARCH = YesPlease
666+
USE_ST_TIMESPEC = YesPlease
660667
endif
661668
ifeq ($(uname_S),SunOS)
662669
NEEDS_SOCKET = YesPlease
@@ -734,6 +741,7 @@ ifeq ($(uname_S),AIX)
734741
NO_MEMMEM = YesPlease
735742
NO_MKDTEMP = YesPlease
736743
NO_STRLCPY = YesPlease
744+
NO_NSEC = YesPlease
737745
FREAD_READS_DIRECTORIES = UnfortunatelyYes
738746
INTERNAL_QSORT = UnfortunatelyYes
739747
NEEDS_LIBICONV=YesPlease
@@ -799,6 +807,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
799807
RUNTIME_PREFIX = YesPlease
800808
NO_POSIX_ONLY_PROGRAMS = YesPlease
801809
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
810+
NO_NSEC = YesPlease
802811
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
803812
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
804813
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
@@ -920,6 +929,15 @@ endif
920929
ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
921930
BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
922931
endif
932+
ifdef USE_NSEC
933+
BASIC_CFLAGS += -DUSE_NSEC
934+
endif
935+
ifdef USE_ST_TIMESPEC
936+
BASIC_CFLAGS += -DUSE_ST_TIMESPEC
937+
endif
938+
ifdef NO_NSEC
939+
BASIC_CFLAGS += -DNO_NSEC
940+
endif
923941
ifdef NO_C99_FORMAT
924942
BASIC_CFLAGS += -DNO_C99_FORMAT
925943
endif

builtin-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
148148
if (pathspec) {
149149
const char **p;
150150
for (p = pathspec; *p; p++) {
151-
if (has_symlink_leading_path(strlen(*p), *p)) {
151+
if (has_symlink_leading_path(*p, strlen(*p))) {
152152
int len = prefix ? strlen(prefix) : 0;
153153
die("'%s' is beyond a symbolic link", *p + len);
154154
}

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ static int check_to_create_blob(const char *new_name, int ok_if_exists)
23602360
* In such a case, path "new_name" does not exist as
23612361
* far as git is concerned.
23622362
*/
2363-
if (has_symlink_leading_path(strlen(new_name), new_name))
2363+
if (has_symlink_leading_path(new_name, strlen(new_name)))
23642364
return 0;
23652365

23662366
return error("%s: already exists in working directory", new_name);

builtin-fetch-pack.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,15 +800,13 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
800800
int fd;
801801

802802
mtime.sec = st.st_mtime;
803-
#ifdef USE_NSEC
804-
mtime.usec = st.st_mtim.usec;
805-
#endif
803+
mtime.nsec = ST_MTIME_NSEC(st);
806804
if (stat(shallow, &st)) {
807805
if (mtime.sec)
808806
die("shallow file was removed during fetch");
809807
} else if (st.st_mtime != mtime.sec
810808
#ifdef USE_NSEC
811-
|| st.st_mtim.usec != mtime.usec
809+
|| ST_MTIME_NSEC(st) != mtime.nsec
812810
#endif
813811
)
814812
die("shallow file was changed during fetch");

builtin-update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int process_path(const char *path)
195195
struct stat st;
196196

197197
len = strlen(path);
198-
if (has_symlink_leading_path(len, path))
198+
if (has_symlink_leading_path(path, len))
199199
return error("'%s' is beyond a symbolic link", path);
200200

201201
/*

cache.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ struct ondisk_cache_entry_extended {
140140
};
141141

142142
struct cache_entry {
143-
unsigned int ce_ctime;
144-
unsigned int ce_mtime;
143+
struct cache_time ce_ctime;
144+
struct cache_time ce_mtime;
145145
unsigned int ce_dev;
146146
unsigned int ce_ino;
147147
unsigned int ce_mode;
@@ -282,7 +282,7 @@ struct index_state {
282282
struct cache_entry **cache;
283283
unsigned int cache_nr, cache_alloc, cache_changed;
284284
struct cache_tree *cache_tree;
285-
time_t timestamp;
285+
struct cache_time timestamp;
286286
void *alloc;
287287
unsigned name_hash_initialized : 1,
288288
initialized : 1;
@@ -428,7 +428,7 @@ extern int read_index_preload(struct index_state *, const char **pathspec);
428428
extern int read_index_from(struct index_state *, const char *path);
429429
extern int is_index_unborn(struct index_state *);
430430
extern int read_index_unmerged(struct index_state *);
431-
extern int write_index(const struct index_state *, int newfd);
431+
extern int write_index(struct index_state *, int newfd);
432432
extern int discard_index(struct index_state *);
433433
extern int unmerged_index(const struct index_state *);
434434
extern int verify_path(const char *path);
@@ -443,6 +443,7 @@ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int opt
443443
extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
444444
extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
445445
extern int remove_index_entry_at(struct index_state *, int pos);
446+
extern void remove_marked_cache_entries(struct index_state *istate);
446447
extern int remove_file_from_index(struct index_state *, const char *path);
447448
#define ADD_CACHE_VERBOSE 1
448449
#define ADD_CACHE_PRETEND 2
@@ -725,11 +726,13 @@ struct checkout {
725726
};
726727

727728
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
728-
extern int has_symlink_leading_path(int len, const char *name);
729-
extern int has_symlink_or_noent_leading_path(int len, const char *name);
730-
extern int has_dirs_only_path(int len, const char *name, int prefix_len);
731-
extern void invalidate_lstat_cache(int len, const char *name);
729+
extern int has_symlink_leading_path(const char *name, int len);
730+
extern int has_symlink_or_noent_leading_path(const char *name, int len);
731+
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
732+
extern void invalidate_lstat_cache(const char *name, int len);
732733
extern void clear_lstat_cache(void);
734+
extern void schedule_dir_for_removal(const char *name, int len);
735+
extern void remove_scheduled_dirs(void);
733736

734737
extern struct alternate_object_database {
735738
struct alternate_object_database *next;

combine-diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
712712
result_size = buf.len;
713713
result = strbuf_detach(&buf, NULL);
714714
elem->mode = canon_mode(st.st_mode);
715-
}
716-
else if (0 <= (fd = open(elem->path, O_RDONLY)) &&
717-
!fstat(fd, &st)) {
715+
} else if (0 <= (fd = open(elem->path, O_RDONLY))) {
718716
size_t len = xsize_t(st.st_size);
719717
ssize_t done;
720718
int is_file, i;

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
3131
return -1;
3232
return 1;
3333
}
34-
if (has_symlink_leading_path(ce_namelen(ce), ce->name))
34+
if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
3535
return 1;
3636
if (S_ISDIR(st->st_mode)) {
3737
unsigned char sub[20];

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
720720
{
721721
struct path_simplify *simplify;
722722

723-
if (has_symlink_leading_path(strlen(path), path))
723+
if (has_symlink_leading_path(path, strlen(path)))
724724
return dir->nr;
725725

726726
simplify = create_simplify(pathspec);

0 commit comments

Comments
 (0)