write_entry(): use fstat() instead of lstat() when file is open
Currently inside write_entry() we do an lstat(path, &st) call on a file which have just been opened inside the exact same function. It should be better to call fstat(fd, &st) on the file while it is open, and it should be at least as fast as the lstat() method. Signed-off-by: Kjetil Barvik <barvik@broadpark.no> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
4857c761e3
commit
e4c7292353
10
entry.c
10
entry.c
|
@ -94,11 +94,12 @@ static void *read_blob_entry(struct cache_entry *ce, unsigned long *size)
|
||||||
static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile)
|
static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile)
|
||||||
{
|
{
|
||||||
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
|
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
|
||||||
int fd, ret;
|
int fd, ret, fstat_done = 0;
|
||||||
char *new;
|
char *new;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
size_t wrote, newsize = 0;
|
size_t wrote, newsize = 0;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
switch (ce_mode_s_ifmt) {
|
switch (ce_mode_s_ifmt) {
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
@ -145,6 +146,11 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
|
||||||
}
|
}
|
||||||
|
|
||||||
wrote = write_in_full(fd, new, size);
|
wrote = write_in_full(fd, new, size);
|
||||||
|
/* use fstat() only when path == ce->name */
|
||||||
|
if (state->refresh_cache && !to_tempfile && !state->base_dir_len) {
|
||||||
|
fstat(fd, &st);
|
||||||
|
fstat_done = 1;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
free(new);
|
free(new);
|
||||||
if (wrote != size)
|
if (wrote != size)
|
||||||
|
@ -161,7 +167,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->refresh_cache) {
|
if (state->refresh_cache) {
|
||||||
struct stat st;
|
if (!fstat_done)
|
||||||
lstat(ce->name, &st);
|
lstat(ce->name, &st);
|
||||||
fill_stat_cache_info(ce, &st);
|
fill_stat_cache_info(ce, &st);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue