cat-file: disable refs/replace with --batch-all-objects

When we're enumerating all objects in the object database, it doesn't
make sense to respect refs/replace. The point of this option is to
enumerate all of the objects in the database at a low level. By
definition we'd already show the replacement object's contents (under
its real oid), and showing those contents under another oid is almost
certainly working against what the user is trying to do.

Note that you could make the same argument for something like:

  git show-index <foo.idx |
  awk '{print $2}' |
  git cat-file --batch

but there we can't know in cat-file exactly what the user intended,
because we don't know the source of the input. They could be trying to
do low-level debugging, or they could be doing something more high-level
(e.g., imagine a porcelain built around cat-file for its object
accesses). So in those cases, we'll have to rely on the user specifying
"git --no-replace-objects" to tell us what to do.

One _could_ make an argument that "cat-file --batch" is sufficiently
low-level plumbing that it should not respect replace-objects at all
(and the caller should do any replacement if they want it).  But we have
been doing so for some time. The history is a little tangled:

  - looking back as far as v1.6.6, we would not respect replace refs for
    --batch-check, but would for --batch (because the former used
    sha1_object_info(), and the replace mechanism only affected actual
    object reads)

  - this discrepancy was made even weirder by 98e2092b50 (cat-file:
    teach --batch to stream blob objects, 2013-07-10), where we always
    output the header using the --batch-check code, and then printed the
    object separately. This could lead to "cat-file --batch" dying (when
    it notices the size or type changed for a non-blob object) or even
    producing bogus output (in streaming mode, we didn't notice that we
    wrote the wrong number of bytes).

  - that persisted until 1f7117ef7a (sha1_file: perform object
    replacement in sha1_object_info_extended(), 2013-12-11), which then
    respected replace refs for both forms.

So it has worked reliably this way for over 7 years, and we should make
sure it continues to do so. That could also be an argument that
--batch-all-objects should not change behavior (which this patch is
doing), but I really consider the current behavior to be an unintended
bug. It's a side effect of how the code is implemented (feeding the oids
back into oid_object_info() rather than looking at what we found while
reading the loose and packed object storage).

The implementation is straight-forward: we just disable the global
read_replace_refs flag when we're in --batch-all-objects mode. It would
perhaps be a little cleaner to change the flag we pass to
oid_object_info_extended(), but that's not enough. We also read objects
via read_object_file() and stream_blob_to_fd(). The former could switch
to its _extended() form, but the streaming code has no mechanism for
disabling replace refs. Setting the global flag works, and as a bonus,
it's impossible to have any "oops, we're sometimes replacing the object
and sometimes not" bugs in the output (like the ones caused by
98e2092b50 above).

The tests here cover the regular-input and --batch-all-objects cases,
for both --batch-check and --batch. There is a test in t6050 that covers
the regular-input case with --batch already, but this new one goes much
further in actually verifying the output (plus covering --batch-check
explicitly). This is perhaps a little overkill and the tests would be
simpler just covering --batch-check, but I wanted to make sure we're
checking that --batch output is consistent between the header and the
content. The global-flag technique used here makes that easy to get
right, but this is future-proofing us against regressions.

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

Build status

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-<commandname>.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://lore.kernel.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