From: Junio C Hamano Date: Mon, 10 Sep 2012 22:24:53 +0000 (-0700) Subject: Merge branch 'jk/maint-null-in-trees' into maint-1.7.11 X-Git-Tag: v1.7.11.6~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03adeeaad6c039aadda074de9509f4d845739d55;p=thirdparty%2Fgit.git Merge branch 'jk/maint-null-in-trees' into maint-1.7.11 "git diff" had a confusion between taking data from a path in the working tree and taking data from an object that happens to have name 0{40} recorded in a tree. * jk/maint-null-in-trees: fsck: detect null sha1 in tree entries do not write null sha1s to on-disk index diff: do not use null sha1 as a sentinel value --- 03adeeaad6c039aadda074de9509f4d845739d55 diff --cc builtin.h index cd9141932b,47f540f37f..dffb34ef4e --- a/builtin.h +++ b/builtin.h @@@ -41,10 -41,8 +41,10 @@@ int copy_note_for_rewrite(struct notes_ void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c); extern int check_pager_config(const char *cmd); +struct diff_options; +extern void setup_diff_pager(struct diff_options *); - extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, char **buf, unsigned long *buf_size); + extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size); extern int cmd_add(int argc, const char **argv, const char *prefix); extern int cmd_annotate(int argc, const char **argv, const char *prefix); diff --cc diff-no-index.c index 7d805a06af,6568eea6f4..0b46a0f79f --- a/diff-no-index.c +++ b/diff-no-index.c @@@ -58,38 -51,8 +58,38 @@@ static int get_mode(const char *path, i return 0; } +static int populate_from_stdin(struct diff_filespec *s) +{ + struct strbuf buf = STRBUF_INIT; + size_t size = 0; + + if (strbuf_read(&buf, 0, 0) < 0) + return error("error while reading from stdin %s", + strerror(errno)); + + s->should_munmap = 0; + s->data = strbuf_detach(&buf, &size); + s->size = size; + s->should_free = 1; + s->is_stdin = 1; + return 0; +} + +static struct diff_filespec *noindex_filespec(const char *name, int mode) +{ + struct diff_filespec *s; + + if (!name) + name = "/dev/null"; + s = alloc_filespec(name); - fill_filespec(s, null_sha1, mode); ++ fill_filespec(s, null_sha1, 0, mode); + if (name == file_from_standard_input) + populate_from_stdin(s); + return s; +} + static int queue_diff(struct diff_options *o, - const char *name1, const char *name2) + const char *name1, const char *name2) { int mode1 = 0, mode2 = 0; diff --cc read-cache.c index b645827c06,5ae7f2b680..7d4bf68e33 --- a/read-cache.c +++ b/read-cache.c @@@ -1790,10 -1615,11 +1790,12 @@@ int write_index(struct index_state *ist continue; if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce)) ce_smudge_racily_clean_entry(ce); + if (is_null_sha1(ce->sha1)) + return error("cache entry has null sha1: %s", ce->name); - if (ce_write_entry(&c, newfd, ce) < 0) + if (ce_write_entry(&c, newfd, ce, previous_name) < 0) return -1; } + strbuf_release(&previous_name_buf); /* Write extension data here */ if (istate->cache_tree) {