rev-list: allow cached objects in existence check

This fixes a regression in 7c0fe330d5 (rev-list: handle missing tree
objects properly, 2018-10-05) where rev-list will now complain about the
empty tree when it doesn't physically exist on disk.

Before that commit, we relied on the traversal code in list-objects.c to
walk through the trees. Since it uses parse_tree(), we'd do a normal
object lookup that includes looking in the set of "cached" objects
(which is where our magic internal empty-tree kicks in).

After that commit, we instead tell list-objects.c not to die on any
missing trees, and we check them ourselves using has_object_file(). But
that function uses OBJECT_INFO_SKIP_CACHED, which means we won't use our
internal empty tree.

This normally wouldn't come up. For most operations, Git will try to
write out the empty tree object as it would any other object. And
pack-objects in a push or fetch will send the empty tree (even if it's
virtual on the sending side). However, there are cases where this can
matter. One I found in the wild:

  1. The root tree of a commit became empty by deleting all files,
     without using an index. In this case it was done using libgit2's
     tree builder API, but as the included test shows, it can easily be
     done with regular git using hash-object.

     The resulting repo works OK, as we'd avoid walking over our own
     reachable commits for a connectivity check.

  2. Cloning with --reference pointing to the repository from (1) can
     trigger the problem, because we tell the other side we already have
     that commit (and hence the empty tree), but then walk over it
     during the connectivity check (where we complain about it missing).

Arguably the workflow in step (1) should be more careful about writing
the empty tree object if we're referencing it. But this workflow did
work prior to 7c0fe330d5, so let's restore it.

This patch makes the minimal fix, which is to swap out a direct call to
oid_object_info_extended(), minus the SKIP_CACHED flag, instead of
calling has_object_file(). This is all that has_object_file() is doing
under the hood. And there's little danger of unrelated fallout from
other unexpected "cached" objects, since there's only one call site that
ends such a cached object, and it's in git-blame.

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