summaryrefslogtreecommitdiff
path: root/builtin-commit.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-05-09 09:11:43 -0700
committerJunio C Hamano <gitster@pobox.com>2008-05-10 18:16:30 -0700
commitd177cab0480f9fa172103071203fed1bff95f5c2 (patch)
treeb864a5d65713a74315730aa4222f44bf1149ce06 /builtin-commit.c
parent2855e70ad11abf7e7f30f975b063bd60d5abdf4f (diff)
downloadgit-d177cab0480f9fa172103071203fed1bff95f5c2.tar.gz
Avoid some unnecessary lstat() calls
The commit sequence used to do if (file_exists(p->path)) add_file_to_cache(p->path, 0); where both "file_exists()" and "add_file_to_cache()" needed to do a lstat() on the path to do their work. This cuts down 'lstat()' calls for the partial commit case by two for each path we know about (because we do this twice per path). Just move the lstat() to the caller instead (that's all that "file_exists()" really does), and pass the stat information down to the add_to_cache() function. This essentially makes 'add_to_index()' the core function that adds a path to the index, getting the index pointer, the pathname and the stat information as arguments. There are then shorthand helper functions that use this core function: - 'add_to_cache()' is just 'add_to_index()' with the default index - 'add_file_to_cache/index()' is the same, but does the lstat() call itself, so you can pass just the pathname if you don't already have the stat information available. So old users of the 'add_file_to_xyzzy()' are essentially left unchanged, and this just exposes the more generic helper function that can take existing stat information into account. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-commit.c')
-rw-r--r--builtin-commit.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin-commit.c b/builtin-commit.c
index 256181a68b..6433f86cbb 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -175,9 +175,11 @@ static void add_remove_files(struct path_list *list)
{
int i;
for (i = 0; i < list->nr; i++) {
+ struct stat st;
struct path_list_item *p = &(list->items[i]);
- if (file_exists(p->path))
- add_file_to_cache(p->path, 0);
+
+ if (!lstat(p->path, &st))
+ add_to_cache(p->path, &st, 0);
else
remove_file_from_cache(p->path);
}