git/builtin
Jeff King e54501004a diff: do not use null sha1 as a sentinel value
The diff code represents paths using the diff_filespec
struct. This struct has a sha1 to represent the sha1 of the
content at that path, as well as a sha1_valid member which
indicates whether its sha1 field is actually useful. If
sha1_valid is not true, then the filespec represents a
working tree file (e.g., for the no-index case, or for when
the index is not up-to-date).

The diff_filespec is only used internally, though. At the
interfaces to the diff subsystem, callers feed the sha1
directly, and we create a diff_filespec from it. It's at
that point that we look at the sha1 and decide whether it is
valid or not; callers may pass the null sha1 as a sentinel
value to indicate that it is not.

We should not typically see the null sha1 coming from any
other source (e.g., in the index itself, or from a tree).
However, a corrupt tree might have a null sha1, which would
cause "diff --patch" to accidentally diff the working tree
version of a file instead of treating it as a blob.

This patch extends the edges of the diff interface to accept
a "sha1_valid" flag whenever we accept a sha1, and to use
that flag when creating a filespec. In some cases, this
means passing the flag through several layers, making the
code change larger than would be desirable.

One alternative would be to simply die() upon seeing
corrupted trees with null sha1s. However, this fix more
directly addresses the problem (while bogus sha1s in a tree
are probably a bad thing, it is really the sentinel
confusion sending us down the wrong code path that is what
makes it devastating). And it means that git is more capable
of examining and debugging these corrupted trees. For
example, you can still "diff --raw" such a tree to find out
when the bogus entry was introduced; you just cannot do a
"--patch" diff (just as you could not with any other
corrupted tree, as we do not have any content to diff).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-29 15:04:32 -07:00
..
add.c Merge branch 'js/add-e-submodule-fix' into maint 2012-02-13 11:42:18 -08:00
annotate.c
apply.c Use correct grammar in diffstat summary line 2012-02-03 23:19:42 -08:00
archive.c Revert "upload-archive: use start_command instead of fork" 2011-11-15 15:39:33 -08:00
bisect--helper.c bisect: introduce support for --no-checkout option. 2011-08-04 15:34:32 -07:00
blame.c diff: do not use null sha1 as a sentinel value 2012-07-29 15:04:32 -07:00
branch.c Merge branch 'cn/maint-branch-with-bad' into maint 2012-03-04 22:17:52 -08:00
bundle.c Teach progress eye-candy to fetch_refs_from_bundle() 2011-09-19 11:07:21 -07:00
cat-file.c diff: do not use null sha1 as a sentinel value 2012-07-29 15:04:32 -07:00
check-attr.c Merge branch 'bc/attr-ignore-case' 2011-10-17 21:37:14 -07:00
check-ref-format.c Change check_refname_format() to reject unnormalized refnames 2011-10-05 13:45:30 -07:00
checkout-index.c checkout-index: remove obsolete comment 2011-08-17 10:39:47 -07:00
checkout.c Merge branch 'jc/checkout-out-of-unborn' into maint 2012-02-16 14:18:06 -08:00
clean.c Documentation: clarify "git clean -e <pattern>" 2011-08-28 23:47:55 -07:00
clone.c Merge branch 'cb/transfer-no-progress' into maint 2012-02-21 15:14:37 -08:00
commit-tree.c Merge branch 'jc/show-sig' 2012-01-06 12:44:07 -08:00
commit.c Merge branch 'jx/i18n-more-marking' into maint 2012-02-16 13:59:53 -08:00
config.c Merge branch 'jv/maint-config-set' into maint 2011-12-28 12:03:19 -08:00
count-objects.c
describe.c describe: Refresh the index when run with --dirty 2011-09-23 14:28:17 -07:00
diff-files.c
diff-index.c
diff-tree.c diffcore-rename: fall back to -C when -C -C busts the rename limit 2011-03-22 14:29:07 -07:00
diff.c diff: do not use null sha1 as a sentinel value 2012-07-29 15:04:32 -07:00
fast-export.c Fix an enum assignment issue spotted by Sun Studio 2011-12-21 10:19:04 -08:00
fetch-pack.c push/fetch/clone --no-progress suppresses progress output 2012-02-13 13:06:53 -08:00
fetch.c push/fetch/clone --no-progress suppresses progress output 2012-02-13 13:06:53 -08:00
fmt-merge-msg.c Convert resolve_ref+xstrdup to new resolve_refdup function 2011-12-13 09:26:52 -08:00
for-each-ref.c Convert resolve_ref+xstrdup to new resolve_refdup function 2011-12-13 09:26:52 -08:00
fsck.c Rename resolve_ref() to resolve_ref_unsafe() 2011-12-13 09:39:46 -08:00
gc.c prune: handle --progress/no-progress 2011-11-07 22:12:19 -08:00
grep.c Merge branch 'jk/grep-binary-attribute' into maint 2012-02-21 14:57:05 -08:00
hash-object.c index_fd(): turn write_object and format_check arguments into one flag 2011-05-09 11:58:19 -07:00
help.c
index-pack.c Appease Sun Studio by renaming "tmpfile" 2011-12-21 10:21:04 -08:00
init-db.c builtin/init-db.c: eliminate -Wformat warning on Solaris 2011-12-20 16:02:08 -08:00
log.c Sync with v1.7.8.1 2011-12-21 12:02:44 -08:00
ls-files.c Merge branch 'cb/common-prefix-unification' 2011-10-10 15:56:17 -07:00
ls-remote.c Merge branch 'jc/ls-remote-short-help' 2011-10-05 12:36:26 -07:00
ls-tree.c Ensure git ls-tree exits with a non-zero exit code if read_tree_recursive fails. 2011-07-25 10:50:11 -07:00
mailinfo.c mailinfo: always clean up rfc822 header folding 2011-05-26 14:13:38 -07:00
mailsplit.c
merge-base.c Documentation: update to git-merge-base --octopus 2011-04-15 10:13:52 -07:00
merge-file.c
merge-index.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
merge-ours.c
merge-recursive.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
merge-tree.c sparse: Fix an "symbol 'merge_file' not decared" warning 2011-04-11 10:35:25 -07:00
merge.c merge: backport GIT_MERGE_AUTOEDIT support 2012-03-20 15:39:10 -07:00
mktag.c read_sha1_file(): get rid of read_sha1_file_repl() madness 2011-05-15 15:23:33 -07:00
mktree.c Merge "Move 'builtin-*' into a 'builtin/' subdirectory" 2011-11-10 09:10:51 -08:00
mv.c Merge branch 'jk/maint-mv' into maint 2011-12-28 11:32:36 -08:00
name-rev.c Merge branch 'jc/maint-name-rev-all' into maint-1.7.6 2011-12-13 21:12:34 -08:00
notes.c Merge branch 'nd/war-on-nul-in-commit' 2011-12-22 11:27:26 -08:00
pack-objects.c Merge branch 'maint' 2012-01-12 23:33:39 -08:00
pack-redundant.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
pack-refs.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
patch-id.c patch-id.c: use strbuf instead of a fixed buffer 2011-09-22 09:35:07 -07:00
prune-packed.c
prune.c prune: handle --progress/no-progress 2011-11-07 22:12:19 -08:00
push.c push/fetch/clone --no-progress suppresses progress output 2012-02-13 13:06:53 -08:00
read-tree.c Teach read-tree the -n|--dry-run option 2011-05-25 15:04:25 -07:00
receive-pack.c Merge branch 'cb/receive-pack-keep-errors' into maint 2012-02-21 15:14:41 -08:00
reflog.c prune: show progress while marking reachable objects 2011-11-07 22:12:19 -08:00
remote-ext.c Remove unused variables 2011-03-22 11:43:27 -07:00
remote-fd.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
remote.c Merge branch 'pj/remote-set-branches-usage-fix' into maint 2012-02-27 15:33:33 -08:00
replace.c Convert many resolve_ref() calls to read_ref*() and ref_exists() 2011-11-13 12:21:06 -08:00
rerere.c rerere: libify rerere_clear() and rerere_gc() 2011-05-08 12:55:34 -07:00
reset.c reset: update cache-tree data when appropriate 2011-12-06 15:13:39 -08:00
rev-list.c rev-list: fix --verify-objects --quiet becoming --objects 2012-02-28 10:47:30 -08:00
rev-parse.c rev-parse: add option --resolve-git-dir <path> 2011-08-16 11:04:31 -07:00
revert.c Merge branch 'maint-1.7.8' into maint 2012-03-20 15:53:30 -07:00
rm.c i18n: git-rm basic messages 2011-03-09 23:52:56 -08:00
send-pack.c push/fetch/clone --no-progress suppresses progress output 2012-02-13 13:06:53 -08:00
shortlog.c Merge branch 'jk/format-patch-am' 2011-05-31 12:19:11 -07:00
show-branch.c Rename resolve_ref() to resolve_ref_unsafe() 2011-12-13 09:39:46 -08:00
show-ref.c Convert many resolve_ref() calls to read_ref*() and ref_exists() 2011-11-13 12:21:06 -08:00
stripspace.c Update documentation for stripspace 2011-12-12 16:48:54 -08:00
symbolic-ref.c Rename resolve_ref() to resolve_ref_unsafe() 2011-12-13 09:39:46 -08:00
tag.c Merge branch 'jk/maint-tag-show-fixes' into maint 2012-02-13 23:31:27 -08:00
tar-tree.c
unpack-file.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
unpack-objects.c zlib: zlib can only process 4GB at a time 2011-06-10 11:52:15 -07:00
update-index.c plug a few coverity-spotted leaks 2011-06-20 14:27:36 -07:00
update-ref.c update-ref: whitespace fix 2011-08-25 14:42:11 -07:00
update-server-info.c
upload-archive.c upload-archive: use start_command instead of fork 2011-11-21 14:32:40 -08:00
var.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
verify-pack.c verify-pack: use index-pack --verify 2011-06-05 22:45:38 -07:00
verify-tag.c Split GPG interface into its own helper library 2011-11-04 21:40:25 -07:00
write-tree.c