sha1_file: use strbuf_add() instead of strbuf_addf()

Replace use of strbuf_addf() with strbuf_add() when enumerating
loose objects in for_each_file_in_obj_subdir(). Since we already
check the length and hex-values of the string before consuming
the path, we can prevent extra computation by using the lower-
level method.

One consumer of for_each_file_in_obj_subdir() is the abbreviation
code. OID abbreviations use a cached list of loose objects (per
object subdirectory) to make repeated queries fast, but there is
significant cache load time when there are many loose objects.

Most repositories do not have many loose objects before repacking,
but in the GVFS case the repos can grow to have millions of loose
objects. Profiling 'git log' performance in GitForWindows on a
GVFS-enabled repo with ~2.5 million loose objects revealed 12% of
the CPU time was spent in strbuf_addf().

Add a new performance test to p4211-line-log.sh that is more
sensitive to this cache-loading. By limiting to 1000 commits, we
more closely resemble user wait time when reading history into a
pager.

For a copy of the Linux repo with two ~512 MB packfiles and ~572K
loose objects, running 'git log --oneline --parents --raw -1000'
had the following performance:

 HEAD~1            HEAD
----------------------------------------
 7.70(7.15+0.54)   7.44(7.09+0.29) -3.4%

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: 196a45db2152de2de42ed3b71a66d04dd40aa08b
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. perl/
  14. po/
  15. ppc/
  16. refs/
  17. sha1dc/
  18. t/
  19. templates/
  20. vcs-svn/
  21. xdiff/
  22. .clang-format
  23. .gitattributes
  24. .gitignore
  25. .gitmodules
  26. .mailmap
  27. .travis.yml
  28. .tsan-suppressions
  29. abspath.c
  30. aclocal.m4
  31. advice.c
  32. advice.h
  33. alias.c
  34. alloc.c
  35. apply.c
  36. apply.h
  37. archive-tar.c
  38. archive-zip.c
  39. archive.c
  40. archive.h
  41. argv-array.c
  42. argv-array.h
  43. attr.c
  44. attr.h
  45. base85.c
  46. bisect.c
  47. bisect.h
  48. blame.c
  49. blame.h
  50. blob.c
  51. blob.h
  52. branch.c
  53. branch.h
  54. builtin.h
  55. bulk-checkin.c
  56. bulk-checkin.h
  57. bundle.c
  58. bundle.h
  59. cache-tree.c
  60. cache-tree.h
  61. cache.h
  62. check-builtins.sh
  63. check-racy.c
  64. check_bindir
  65. color.c
  66. color.h
  67. column.c
  68. column.h
  69. combine-diff.c
  70. command-list.txt
  71. commit-slab.h
  72. commit.c
  73. commit.h
  74. common-main.c
  75. config.c
  76. config.h
  77. config.mak.in
  78. config.mak.uname
  79. configure.ac
  80. connect.c
  81. connect.h
  82. connected.c
  83. connected.h
  84. convert.c
  85. convert.h
  86. copy.c
  87. COPYING
  88. credential-cache--daemon.c
  89. credential-cache.c
  90. credential-store.c
  91. credential.c
  92. credential.h
  93. csum-file.c
  94. csum-file.h
  95. ctype.c
  96. daemon.c
  97. date.c
  98. decorate.c
  99. decorate.h
  100. delta.h
  101. diff-delta.c
  102. diff-lib.c
  103. diff-no-index.c
  104. diff.c
  105. diff.h
  106. diffcore-break.c
  107. diffcore-delta.c
  108. diffcore-order.c
  109. diffcore-pickaxe.c
  110. diffcore-rename.c
  111. diffcore.h
  112. dir-iterator.c
  113. dir-iterator.h
  114. dir.c
  115. dir.h
  116. editor.c
  117. entry.c
  118. environment.c
  119. exec_cmd.c
  120. exec_cmd.h
  121. fast-import.c
  122. fetch-pack.c
  123. fetch-pack.h
  124. fmt-merge-msg.h
  125. fsck.c
  126. fsck.h
  127. fsmonitor.c
  128. fsmonitor.h
  129. generate-cmdlist.sh
  130. gettext.c
  131. gettext.h
  132. git-add--interactive.perl
  133. git-archimport.perl
  134. git-bisect.sh
  135. git-compat-util.h
  136. git-cvsexportcommit.perl
  137. git-cvsimport.perl
  138. git-cvsserver.perl
  139. git-difftool--helper.sh
  140. git-filter-branch.sh
  141. git-instaweb.sh
  142. git-merge-octopus.sh
  143. git-merge-one-file.sh
  144. git-merge-resolve.sh
  145. git-mergetool--lib.sh
  146. git-mergetool.sh
  147. git-p4.py
  148. git-parse-remote.sh
  149. git-quiltimport.sh
  150. git-rebase--am.sh
  151. git-rebase--interactive.sh
  152. git-rebase--merge.sh
  153. git-rebase.sh
  154. git-remote-testgit.sh
  155. git-request-pull.sh
  156. git-send-email.perl
  157. git-sh-i18n.sh
  158. git-sh-setup.sh
  159. git-stash.sh
  160. git-submodule.sh
  161. git-svn.perl
  162. GIT-VERSION-GEN
  163. git-web--browse.sh
  164. git.c
  165. git.rc
  166. gpg-interface.c
  167. gpg-interface.h
  168. graph.c
  169. graph.h
  170. grep.c
  171. grep.h
  172. hash.h
  173. hashmap.c
  174. hashmap.h
  175. help.c
  176. help.h
  177. hex.c
  178. http-backend.c
  179. http-fetch.c
  180. http-push.c
  181. http-walker.c
  182. http.c
  183. http.h
  184. ident.c
  185. imap-send.c
  186. INSTALL
  187. iterator.h
  188. khash.h
  189. kwset.c
  190. kwset.h
  191. levenshtein.c
  192. levenshtein.h
  193. LGPL-2.1
  194. line-log.c
  195. line-log.h
  196. line-range.c
  197. line-range.h
  198. list-objects.c
  199. list-objects.h
  200. list.h
  201. ll-merge.c
  202. ll-merge.h
  203. lockfile.c
  204. lockfile.h
  205. log-tree.c
  206. log-tree.h
  207. mailinfo.c
  208. mailinfo.h
  209. mailmap.c
  210. mailmap.h
  211. Makefile
  212. match-trees.c
  213. merge-blobs.c
  214. merge-blobs.h
  215. merge-recursive.c
  216. merge-recursive.h
  217. merge.c
  218. mergesort.c
  219. mergesort.h
  220. mru.c
  221. mru.h
  222. name-hash.c
  223. notes-cache.c
  224. notes-cache.h
  225. notes-merge.c
  226. notes-merge.h
  227. notes-utils.c
  228. notes-utils.h
  229. notes.c
  230. notes.h
  231. object.c
  232. object.h
  233. oidmap.c
  234. oidmap.h
  235. oidset.c
  236. oidset.h
  237. pack-bitmap-write.c
  238. pack-bitmap.c
  239. pack-bitmap.h
  240. pack-check.c
  241. pack-objects.c
  242. pack-objects.h
  243. pack-revindex.c
  244. pack-revindex.h
  245. pack-write.c
  246. pack.h
  247. packfile.c
  248. packfile.h
  249. pager.c
  250. parse-options-cb.c
  251. parse-options.c
  252. parse-options.h
  253. patch-delta.c
  254. patch-ids.c
  255. patch-ids.h
  256. path.c
  257. path.h
  258. pathspec.c
  259. pathspec.h
  260. pkt-line.c
  261. pkt-line.h
  262. preload-index.c
  263. pretty.c
  264. prio-queue.c
  265. prio-queue.h
  266. progress.c
  267. progress.h
  268. prompt.c
  269. prompt.h
  270. quote.c
  271. quote.h
  272. reachable.c
  273. reachable.h
  274. read-cache.c
  275. README.md
  276. ref-filter.c
  277. ref-filter.h
  278. reflog-walk.c
  279. reflog-walk.h
  280. refs.c
  281. refs.h
  282. remote-curl.c
  283. remote-testsvn.c
  284. remote.c
  285. remote.h
  286. replace_object.c
  287. repository.c
  288. repository.h
  289. rerere.c
  290. rerere.h
  291. resolve-undo.c
  292. resolve-undo.h
  293. revision.c
  294. revision.h
  295. run-command.c
  296. run-command.h
  297. send-pack.c
  298. send-pack.h
  299. sequencer.c
  300. sequencer.h
  301. server-info.c
  302. setup.c
  303. sh-i18n--envsubst.c
  304. sha1-array.c
  305. sha1-array.h
  306. sha1-lookup.c
  307. sha1-lookup.h
  308. sha1_file.c
  309. sha1_name.c
  310. sha1dc_git.c
  311. sha1dc_git.h
  312. shallow.c
  313. shell.c
  314. shortlog.h
  315. show-index.c
  316. sideband.c
  317. sideband.h
  318. sigchain.c
  319. sigchain.h
  320. split-index.c
  321. split-index.h
  322. strbuf.c
  323. strbuf.h
  324. streaming.c
  325. streaming.h
  326. string-list.c
  327. string-list.h
  328. sub-process.c
  329. sub-process.h
  330. submodule-config.c
  331. submodule-config.h
  332. submodule.c
  333. submodule.h
  334. symlinks.c
  335. tag.c
  336. tag.h
  337. tar.h
  338. tempfile.c
  339. tempfile.h
  340. thread-utils.c
  341. thread-utils.h
  342. tmp-objdir.c
  343. tmp-objdir.h
  344. trace.c
  345. trace.h
  346. trailer.c
  347. trailer.h
  348. transport-helper.c
  349. transport.c
  350. transport.h
  351. tree-diff.c
  352. tree-walk.c
  353. tree-walk.h
  354. tree.c
  355. tree.h
  356. unicode_width.h
  357. unimplemented.sh
  358. unix-socket.c
  359. unix-socket.h
  360. unpack-trees.c
  361. unpack-trees.h
  362. upload-pack.c
  363. url.c
  364. url.h
  365. urlmatch.c
  366. urlmatch.h
  367. usage.c
  368. userdiff.c
  369. userdiff.h
  370. utf8.c
  371. utf8.h
  372. varint.c
  373. varint.h
  374. version.c
  375. version.h
  376. versioncmp.c
  377. walker.c
  378. walker.h
  379. wildmatch.c
  380. wildmatch.h
  381. worktree.c
  382. worktree.h
  383. wrap-for-bin.sh
  384. wrapper.c
  385. write_or_die.c
  386. ws.c
  387. wt-status.c
  388. wt-status.h
  389. xdiff-interface.c
  390. xdiff-interface.h
  391. zlib.c
README.md

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at https://public-inbox.org/git/, http://marc.info/?l=git and other archival sites.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks