builtin/pack-objects.c: simplify add_objects_in_unpacked_packs()

This function is used to implement `pack-objects`'s `--keep-unreachable`
option, but can be simplified in a couple of ways:

  - add_objects_in_unpacked_packs() iterates over all packs (and then
    all packed objects) itself, but could use for_each_packed_object()
    instead since the missing flags necessary were added in the previous
    commit

  - objects are added to an in_pack array which store (off_t, object)
    tuples, and then sorted in offset order when we could iterate
    objects in offset order.

    There is a slight behavior change here: before we would have added
    objects in sorted offset order among _all_ packs. Handing objects to
    create_object_entry() in pack order for each pack (instead of
    feeding objects from all packs simultaneously their offset relative
    to different packs) is much more reasonable, if different than how
    the code currently works.

  - objects in a single pack are iterated in index order and searched
    for in order to discover their offsets, which is much less efficient
    than using the on-disk reverse index

Simplify the function by addressing each of the above and moving the
core of the loop into a callback function that we then pass to
for_each_packed_object() instead of open-coding the latter function
ourselves.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 953b67c08bf870f7e7594138bcf26be685e29d04
  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