pack-objects: handle island check for "external" delta base

Two recent topics, jk/pack-delta-reuse-with-bitmap and
cc/delta-islands, can have a funny interaction. When
checking if we can reuse an on-disk delta, the first topic
allows base_entry to be NULL when we find an object that's
not in the packing list. But the latter topic introduces a
call to in_same_island(), which needs to look at
base_entry->idx.oid. When these two features are used
together, we might try to dereference a NULL base_entry.

In practice, this doesn't really happen. We'd generally only
use delta islands when packing to disk, since the whole
point is to optimize the pack for serving fetches later. And
the new delta-reuse code relies on having used reachability
bitmaps to determine the set of objects, which we would
typically only do when serving an actual fetch.

However, it is technically possible to combine these
features. And even without doing so, building with
"SANITIZE=address,undefined" will cause t5310.46 to
complain.  Even though that test does not have delta islands
enabled, we still take the address of the NULL entry to pass
to in_same_island(). That function then promptly returns
without dereferencing the value when it sees that islands
are not enabled, but it's enough to trigger a sanitizer
error.

The solution is straight-forward: when both features are
used together, we should pass the oid of the found base to
in_same_island().

This is tricky to do inside a single "if" statement. And
after the merge in f3504ea3dd (Merge branch
'cc/delta-islands', 2018-09-17), that "if" condition is
already getting pretty unwieldy. So this patch moves the
logic into a helper function, where we can easily use
multiple return paths. The result is a bit longer, but the
logic should be much easier to follow.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: b1f549999f61405802bfc73522867b7d5043b423
  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. iterator.h
  211. json-writer.c
  212. json-writer.h
  213. khash.h
  214. kwset.c
  215. kwset.h
  216. levenshtein.c
  217. levenshtein.h
  218. LGPL-2.1
  219. line-log.c
  220. line-log.h
  221. line-range.c
  222. line-range.h
  223. linear-assignment.c
  224. linear-assignment.h
  225. list-objects-filter-options.c
  226. list-objects-filter-options.h
  227. list-objects-filter.c
  228. list-objects-filter.h
  229. list-objects.c
  230. list-objects.h
  231. list.h
  232. ll-merge.c
  233. ll-merge.h
  234. lockfile.c
  235. lockfile.h
  236. log-tree.c
  237. log-tree.h
  238. ls-refs.c
  239. ls-refs.h
  240. mailinfo.c
  241. mailinfo.h
  242. mailmap.c
  243. mailmap.h
  244. Makefile
  245. match-trees.c
  246. mem-pool.c
  247. mem-pool.h
  248. merge-blobs.c
  249. merge-blobs.h
  250. merge-recursive.c
  251. merge-recursive.h
  252. merge.c
  253. mergesort.c
  254. mergesort.h
  255. midx.c
  256. midx.h
  257. name-hash.c
  258. notes-cache.c
  259. notes-cache.h
  260. notes-merge.c
  261. notes-merge.h
  262. notes-utils.c
  263. notes-utils.h
  264. notes.c
  265. notes.h
  266. object-store.h
  267. object.c
  268. object.h
  269. oidmap.c
  270. oidmap.h
  271. oidset.c
  272. oidset.h
  273. pack-bitmap-write.c
  274. pack-bitmap.c
  275. pack-bitmap.h
  276. pack-check.c
  277. pack-objects.c
  278. pack-objects.h
  279. pack-revindex.c
  280. pack-revindex.h
  281. pack-write.c
  282. pack.h
  283. packfile.c
  284. packfile.h
  285. pager.c
  286. parse-options-cb.c
  287. parse-options.c
  288. parse-options.h
  289. patch-delta.c
  290. patch-ids.c
  291. patch-ids.h
  292. path.c
  293. path.h
  294. pathspec.c
  295. pathspec.h
  296. pkt-line.c
  297. pkt-line.h
  298. preload-index.c
  299. pretty.c
  300. pretty.h
  301. prio-queue.c
  302. prio-queue.h
  303. progress.c
  304. progress.h
  305. prompt.c
  306. prompt.h
  307. protocol.c
  308. protocol.h
  309. quote.c
  310. quote.h
  311. range-diff.c
  312. range-diff.h
  313. reachable.c
  314. reachable.h
  315. read-cache.c
  316. README.md
  317. ref-filter.c
  318. ref-filter.h
  319. reflog-walk.c
  320. reflog-walk.h
  321. refs.c
  322. refs.h
  323. refspec.c
  324. refspec.h
  325. remote-curl.c
  326. remote-testsvn.c
  327. remote.c
  328. remote.h
  329. replace-object.c
  330. replace-object.h
  331. repository.c
  332. repository.h
  333. rerere.c
  334. rerere.h
  335. resolve-undo.c
  336. resolve-undo.h
  337. revision.c
  338. revision.h
  339. run-command.c
  340. run-command.h
  341. send-pack.c
  342. send-pack.h
  343. sequencer.c
  344. sequencer.h
  345. serve.c
  346. serve.h
  347. server-info.c
  348. setup.c
  349. sh-i18n--envsubst.c
  350. sha1-array.c
  351. sha1-array.h
  352. sha1-file.c
  353. sha1-lookup.c
  354. sha1-lookup.h
  355. sha1-name.c
  356. sha1dc_git.c
  357. sha1dc_git.h
  358. shallow.c
  359. shell.c
  360. shortlog.h
  361. sideband.c
  362. sideband.h
  363. sigchain.c
  364. sigchain.h
  365. split-index.c
  366. split-index.h
  367. strbuf.c
  368. strbuf.h
  369. streaming.c
  370. streaming.h
  371. string-list.c
  372. string-list.h
  373. sub-process.c
  374. sub-process.h
  375. submodule-config.c
  376. submodule-config.h
  377. submodule.c
  378. submodule.h
  379. symlinks.c
  380. tag.c
  381. tag.h
  382. tar.h
  383. tempfile.c
  384. tempfile.h
  385. thread-utils.c
  386. thread-utils.h
  387. tmp-objdir.c
  388. tmp-objdir.h
  389. trace.c
  390. trace.h
  391. trailer.c
  392. trailer.h
  393. transport-helper.c
  394. transport-internal.h
  395. transport.c
  396. transport.h
  397. tree-diff.c
  398. tree-walk.c
  399. tree-walk.h
  400. tree.c
  401. tree.h
  402. unicode-width.h
  403. unimplemented.sh
  404. unix-socket.c
  405. unix-socket.h
  406. unpack-trees.c
  407. unpack-trees.h
  408. upload-pack.c
  409. upload-pack.h
  410. url.c
  411. url.h
  412. urlmatch.c
  413. urlmatch.h
  414. usage.c
  415. userdiff.c
  416. userdiff.h
  417. utf8.c
  418. utf8.h
  419. varint.c
  420. varint.h
  421. version.c
  422. version.h
  423. versioncmp.c
  424. walker.c
  425. walker.h
  426. wildmatch.c
  427. wildmatch.h
  428. worktree.c
  429. worktree.h
  430. wrap-for-bin.sh
  431. wrapper.c
  432. write-or-die.c
  433. ws.c
  434. wt-status.c
  435. wt-status.h
  436. xdiff-interface.c
  437. xdiff-interface.h
  438. 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