unpack_entry: do not die when we fail to apply a delta

When we try to load an object from disk and fail, our
general strategy is to see if we can get it from somewhere
else (e.g., a loose object). That lets users fix corruption
problems by copying known-good versions of objects into the
object database.

We already handle the case where we were not able to read
the delta from disk. However, when we find that the delta we
read does not apply, we simply die.  This case is harder to
trigger, as corruption in the delta data itself would
trigger a crc error from zlib.  However, a corruption that
pointed us at the wrong delta base might cause it.

We can do the same "fail and try to find the object
elsewhere" trick instead of dying. This not only gives us a
chance to recover, but also puts us on code paths that will
alert the user to the problem (with the current message,
they do not even know which sha1 caused the problem).

Note that unlike some other pack corruptions, we do not
recover automatically from this case when doing a repack.
There is nothing apparently wrong with the delta, as it
points to a valid, accessible object, and we realize the
error only when the resulting size does not match up. And in
theory, one could even have a case where the corrupted size
is the same, and the problem would only be noticed by
recomputing the sha1.

We can get around this by recomputing the deltas with
--no-reuse-delta, which our test does (and this is probably
good advice for anyone recovering from pack corruption).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: 8f72c892de4f1342f34e0f2e87bdfe5ea79b66f8
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. mergetools/
  11. perl/
  12. po/
  13. ppc/
  14. t/
  15. templates/
  16. vcs-svn/
  17. xdiff/
  18. .gitattributes
  19. .gitignore
  20. .mailmap
  21. abspath.c
  22. aclocal.m4
  23. advice.c
  24. advice.h
  25. alias.c
  26. alloc.c
  27. archive-tar.c
  28. archive-zip.c
  29. archive.c
  30. archive.h
  31. argv-array.c
  32. argv-array.h
  33. attr.c
  34. attr.h
  35. base85.c
  36. bisect.c
  37. bisect.h
  38. blob.c
  39. blob.h
  40. branch.c
  41. branch.h
  42. builtin.h
  43. bulk-checkin.c
  44. bulk-checkin.h
  45. bundle.c
  46. bundle.h
  47. cache-tree.c
  48. cache-tree.h
  49. cache.h
  50. check-builtins.sh
  51. check-racy.c
  52. check_bindir
  53. color.c
  54. color.h
  55. column.c
  56. column.h
  57. combine-diff.c
  58. command-list.txt
  59. commit.c
  60. commit.h
  61. config.c
  62. config.mak.in
  63. config.mak.uname
  64. configure.ac
  65. connect.c
  66. connected.c
  67. connected.h
  68. convert.c
  69. convert.h
  70. copy.c
  71. COPYING
  72. credential-cache--daemon.c
  73. credential-cache.c
  74. credential-store.c
  75. credential.c
  76. credential.h
  77. csum-file.c
  78. csum-file.h
  79. ctype.c
  80. daemon.c
  81. date.c
  82. decorate.c
  83. decorate.h
  84. delta.h
  85. diff-delta.c
  86. diff-lib.c
  87. diff-no-index.c
  88. diff.c
  89. diff.h
  90. diffcore-break.c
  91. diffcore-delta.c
  92. diffcore-order.c
  93. diffcore-pickaxe.c
  94. diffcore-rename.c
  95. diffcore.h
  96. dir.c
  97. dir.h
  98. editor.c
  99. entry.c
  100. environment.c
  101. exec_cmd.c
  102. exec_cmd.h
  103. fast-import.c
  104. fetch-pack.c
  105. fetch-pack.h
  106. fixup-builtins
  107. fmt-merge-msg.h
  108. fsck.c
  109. fsck.h
  110. generate-cmdlist.sh
  111. gettext.c
  112. gettext.h
  113. git-add--interactive.perl
  114. git-am.sh
  115. git-archimport.perl
  116. git-bisect.sh
  117. git-compat-util.h
  118. git-cvsexportcommit.perl
  119. git-cvsimport.perl
  120. git-cvsserver.perl
  121. git-difftool--helper.sh
  122. git-difftool.perl
  123. git-filter-branch.sh
  124. git-instaweb.sh
  125. git-lost-found.sh
  126. git-merge-octopus.sh
  127. git-merge-one-file.sh
  128. git-merge-resolve.sh
  129. git-mergetool--lib.sh
  130. git-mergetool.sh
  131. git-p4.py
  132. git-parse-remote.sh
  133. git-pull.sh
  134. git-quiltimport.sh
  135. git-rebase--am.sh
  136. git-rebase--interactive.sh
  137. git-rebase--merge.sh
  138. git-rebase.sh
  139. git-relink.perl
  140. git-remote-testgit
  141. git-remote-testpy.py
  142. git-repack.sh
  143. git-request-pull.sh
  144. git-send-email.perl
  145. git-sh-i18n.sh
  146. git-sh-setup.sh
  147. git-stash.sh
  148. git-submodule.sh
  149. git-svn.perl
  150. GIT-VERSION-GEN
  151. git-web--browse.sh
  152. git.c
  153. git.spec.in
  154. gpg-interface.c
  155. gpg-interface.h
  156. graph.c
  157. graph.h
  158. grep.c
  159. grep.h
  160. hash.c
  161. hash.h
  162. help.c
  163. help.h
  164. hex.c
  165. http-backend.c
  166. http-fetch.c
  167. http-push.c
  168. http-walker.c
  169. http.c
  170. http.h
  171. ident.c
  172. imap-send.c
  173. INSTALL
  174. kwset.c
  175. kwset.h
  176. levenshtein.c
  177. levenshtein.h
  178. LGPL-2.1
  179. list-objects.c
  180. list-objects.h
  181. ll-merge.c
  182. ll-merge.h
  183. lockfile.c
  184. log-tree.c
  185. log-tree.h
  186. mailmap.c
  187. mailmap.h
  188. Makefile
  189. match-trees.c
  190. merge-blobs.c
  191. merge-blobs.h
  192. merge-recursive.c
  193. merge-recursive.h
  194. merge.c
  195. mergesort.c
  196. mergesort.h
  197. name-hash.c
  198. notes-cache.c
  199. notes-cache.h
  200. notes-merge.c
  201. notes-merge.h
  202. notes.c
  203. notes.h
  204. object.c
  205. object.h
  206. pack-check.c
  207. pack-refs.c
  208. pack-refs.h
  209. pack-revindex.c
  210. pack-revindex.h
  211. pack-write.c
  212. pack.h
  213. pager.c
  214. parse-options-cb.c
  215. parse-options.c
  216. parse-options.h
  217. patch-delta.c
  218. patch-ids.c
  219. patch-ids.h
  220. path.c
  221. pathspec.c
  222. pathspec.h
  223. pkt-line.c
  224. pkt-line.h
  225. preload-index.c
  226. pretty.c
  227. progress.c
  228. progress.h
  229. prompt.c
  230. prompt.h
  231. quote.c
  232. quote.h
  233. reachable.c
  234. reachable.h
  235. read-cache.c
  236. README
  237. reflog-walk.c
  238. reflog-walk.h
  239. refs.c
  240. refs.h
  241. remote-curl.c
  242. remote-testsvn.c
  243. remote.c
  244. remote.h
  245. replace_object.c
  246. rerere.c
  247. rerere.h
  248. resolve-undo.c
  249. resolve-undo.h
  250. revision.c
  251. revision.h
  252. run-command.c
  253. run-command.h
  254. send-pack.c
  255. send-pack.h
  256. sequencer.c
  257. sequencer.h
  258. server-info.c
  259. setup.c
  260. sh-i18n--envsubst.c
  261. sha1-array.c
  262. sha1-array.h
  263. sha1-lookup.c
  264. sha1-lookup.h
  265. sha1_file.c
  266. sha1_name.c
  267. shallow.c
  268. shell.c
  269. shortlog.h
  270. show-index.c
  271. sideband.c
  272. sideband.h
  273. sigchain.c
  274. sigchain.h
  275. strbuf.c
  276. strbuf.h
  277. streaming.c
  278. streaming.h
  279. string-list.c
  280. string-list.h
  281. submodule.c
  282. submodule.h
  283. symlinks.c
  284. tag.c
  285. tag.h
  286. tar.h
  287. test-chmtime.c
  288. test-ctype.c
  289. test-date.c
  290. test-delta.c
  291. test-dump-cache-tree.c
  292. test-genrandom.c
  293. test-index-version.c
  294. test-line-buffer.c
  295. test-match-trees.c
  296. test-mergesort.c
  297. test-mktemp.c
  298. test-parse-options.c
  299. test-path-utils.c
  300. test-regex.c
  301. test-revision-walking.c
  302. test-run-command.c
  303. test-scrap-cache-tree.c
  304. test-sha1.c
  305. test-sha1.sh
  306. test-sigchain.c
  307. test-string-list.c
  308. test-subprocess.c
  309. test-svn-fe.c
  310. test-wildmatch.c
  311. thread-utils.c
  312. thread-utils.h
  313. trace.c
  314. transport-helper.c
  315. transport.c
  316. transport.h
  317. tree-diff.c
  318. tree-walk.c
  319. tree-walk.h
  320. tree.c
  321. tree.h
  322. unimplemented.sh
  323. unix-socket.c
  324. unix-socket.h
  325. unpack-trees.c
  326. unpack-trees.h
  327. upload-pack.c
  328. url.c
  329. url.h
  330. usage.c
  331. userdiff.c
  332. userdiff.h
  333. utf8.c
  334. utf8.h
  335. varint.c
  336. varint.h
  337. version.c
  338. version.h
  339. walker.c
  340. walker.h
  341. wildmatch.c
  342. wildmatch.h
  343. wrap-for-bin.sh
  344. wrapper.c
  345. write_or_die.c
  346. ws.c
  347. wt-status.c
  348. wt-status.h
  349. xdiff-interface.c
  350. xdiff-interface.h
  351. zlib.c