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

Re: git commit results in many lstat()s

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 1, 2017, 22:11 UTC
Message-ID
<xmqq8tppo92x.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<DA0A42D68346B1469147552440A645039A9C56D4@ORSMSX115.amr.corp.intel.com>
"Gumbel, Matthew K" <matthew.k.gumbel@intel.com> writes:
> I do not understand why git commit must call lstat() on every file
> in the repository, even when I specify the name of the file I want
> to commit on the command line.
Assuming the "COPYING" and "README.md" files are already tracked:
    $ >COPYING
    $ >README.md
    $ git commit COPYING

would open an editor, in which you would see list of files under "Changes to be committed", "Changes not staged for commit", etc. Among the second class you would see README.md listed.

To figure out what paths are "changed", without having to open all files and compare their contents with what is recorded in the commit you are building on top of, we do lstat(2) to see if the timestamp (and other information in the inode) of the files are the same since you checked them out of HEAD.

    $ git commit --no-status COPYING

would reduce the number of lstat(2) somewhat, because the codepath is told that it does not have to make the list to be shown in the editor. So would

    $ git commit -m "empty COPYING" COPYING

These two only halve the number of lstat(2), by taking advantage of the fact that the list of "modified files" does not have to be built. There probably are other things that can be optimized.

Previous: Gumbel, Matthew KNext: Gumbel, Matthew K
Message 2 of 6 in “git commit results in many lstat()s”
  1. Gumbel, Matthew KFeb 1, 2017
  2. Junio C HamanoFeb 1, 2017
  3. Gumbel, Matthew KFeb 1, 2017
  4. Junio C HamanoFeb 1, 2017
  5. Gumbel, Matthew KFeb 2, 2017
  6. brian m. carlsonFeb 2, 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.