git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] commit: Optimize number of lstat() calls

From
Gumbel, Matthew K <matthew.k.gumbel@intel.com>
Date
Feb 3, 2017, 23:22 UTC
Message-ID
<DA0A42D68346B1469147552440A645039A9C9988@ORSMSX115.amr.corp.intel.com>

When making a --only commit, original behavior was to do a full cache update for the purposes of giving the pre-commit hook an up-to-date set of stat data. That would result in long runtime for git-commit in a big repo on NFS (>60s for a 54k-file repo).

With this change, when doing a --only commit and no pre-commit hook is present, the cache update is skipped since it is known a priori which files are to be committed.

This was discussed on the mailing list here: https://public-inbox.org/git/DA0A42D68346B1469147552440A645039A9C56D4@ORSMSX115.amr.corp.intel.com/

Signed-off-by: Matthew K. Gumbel <matthew.k.gumbel@intel.com>
---
builtin/commit.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 2de5f6c..1df3d71 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -470,7 +470,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix

    hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
    add_remove_files(&partial);
-   refresh_cache(REFRESH_QUIET);
+    if (find_hook("pre-commit")) {
+        refresh_cache(REFRESH_QUIET);
+    }
    update_main_cache_tree(WRITE_TREE_SILENT);
    if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
        die(_("unable to write new_index file"));
@@ -482,7 +484,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix

    create_base_index(current_head);
    add_remove_files(&partial);
-   refresh_cache(REFRESH_QUIET);
+    if (find_hook("pre-commit")) {
+        refresh_cache(REFRESH_QUIET);
+    }

    if (write_locked_index(&the_index, &false_lock, CLOSE_LOCK))
        die(_("unable to write temporary index file"));
-- 
2.8.4
Next: Junio C Hamano
Message 1 of 6 in “commit: Optimize number of lstat() calls”
  1. commit: Optimize number of lstat() callsGumbel, Matthew K, Feb 3, 2017
  2. Junio C HamanoFeb 3, 2017
  3. Junio C HamanoFeb 4, 2017
  4. Johannes SchindelinFeb 4, 2017
  5. Junio C HamanoFeb 4, 2017
  6. Johannes SchindelinFeb 4, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.