Merge branch 'jk/maint-null-in-trees' into maint-1.7.11
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Sep 2012 22:24:53 +0000 (15:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Sep 2012 22:24:54 +0000 (15:24 -0700)
"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

14 files changed:
1  2 
builtin.h
builtin/blame.c
builtin/cat-file.c
builtin/diff.c
combine-diff.c
diff-no-index.c
diff.c
diff.h
diffcore-rename.c
diffcore.h
fsck.c
read-cache.c
revision.c
t/t1450-fsck.sh

diff --cc builtin.h
index cd9141932b3d77c3d5c5b04908ea3b3298c4a20d,47f540f37f908c7539bcdbde5dd7550af8c92e72..dffb34ef4e29799bcb9a8c78bdf439547845794f
+++ 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 builtin/blame.c
Simple merge
Simple merge
diff --cc builtin/diff.c
Simple merge
diff --cc combine-diff.c
Simple merge
diff --cc diff-no-index.c
index 7d805a06afacae7eaa36a192e3a16406ef0fb41f,6568eea6f4a465a40f522584a6fcaf92841f16e7..0b46a0f79f1376a935e4a0a408a224de711b60cb
@@@ -58,38 -51,8 +58,38 @@@ static int get_mode(const char *path, i
        return 0;
  }
  
-       fill_filespec(s, null_sha1, mode);
 +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, 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 diff.c
Simple merge
diff --cc diff.h
Simple merge
Simple merge
diff --cc diffcore.h
Simple merge
diff --cc fsck.c
Simple merge
diff --cc read-cache.c
index b645827c06a268ee4721fda5fc8cdcd84775c9ec,5ae7f2b680d8788f4c806d9c6ec111b6ba339aaa..7d4bf68e33d35ebeb5e9f985ac5c9dc2962fc8ba
@@@ -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 (ce_write_entry(&c, newfd, ce) < 0)
+               if (is_null_sha1(ce->sha1))
+                       return error("cache entry has null sha1: %s", ce->name);
 +              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) {
diff --cc revision.c
Simple merge
diff --cc t/t1450-fsck.sh
Simple merge