commit-reach: fix first-parent heuristic

The algorithm in can_all_from_reach_with_flags() performs a depth-
first-search, terminated by generation number, intending to use
a hueristic that "important" commits are found in the first-parent
history. This heuristic is valuable in scenarios like fetch
negotiation.

However, there is a problem! After the search finds a target commit,
it should pop all commits off the stack and mark them as "can reach".
This logic is incorrect, so the algorithm instead walks all reachable
commits above the generation-number cutoff.

The existing algorithm is still an improvement over the previous
algorithm, as the worst-case complexity went from quadratic to linear.
The performance measurement at the time was good, but not dramatic.
By fixing this heuristic, we reduce the number of walked commits.

We can also re-run the performance tests from commit 4fbcca4e
"commit-reach: make can_all_from_reach... linear".

Performance was measured on the Linux repository using
'test-tool reach can_all_from_reach'. The input included rows seeded by
tag values. The "small" case included X-rows as v4.[0-9]* and Y-rows as
v3.[0-9]*. This mimics a (very large) fetch that says "I have all major
v3 releases and want all major v4 releases." The "large" case included
X-rows as "v4.*" and Y-rows as "v3.*". This adds all release-candidate
tags to the set, which does not greatly increase the number of objects
that are considered, but does increase the number of 'from' commits,
demonstrating the quadratic nature of the previous code.

Small Case:

4fbcca4e~1: 0.85 s
  4fbcca4e: 0.26 s (num_walked: 1,011,035)
      HEAD: 0.14 s (num_walked:     8,601)

Large Case:

4fbcca4e~1: 24.0  s
  4fbcca4e:  0.12 s (num_walked:  503,925)
      HEAD:  0.06 s (num_walked:  217,243)

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

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

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