Merge branch 'jh/note-trees-record-blobs'
authorJunio C Hamano <gitster@pobox.com>
Fri, 14 Mar 2014 21:25:39 +0000 (14:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Mar 2014 21:25:39 +0000 (14:25 -0700)
"git notes -C <blob>" should not take an object that is not a blob.

* jh/note-trees-record-blobs:
notes: disallow reusing non-blob as a note object

1  2 
builtin/notes.c
diff --combined builtin/notes.c
index 2b24d059b509d28d587066440ed131ce2f85464f,c11d6e6dc82c3d52329c04a848bf6f02c2768854..bb89930373451eb0637bb92eedd0613513d959fb
@@@ -269,7 -269,11 +269,11 @@@ static int parse_reuse_arg(const struc
                die(_("Failed to resolve '%s' as a valid ref."), arg);
        if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
                free(buf);
-               die(_("Failed to read object '%s'."), arg);;
+               die(_("Failed to read object '%s'."), arg);
+       }
+       if (type != OBJ_BLOB) {
+               free(buf);
+               die(_("Cannot read note data from non-blob object '%s'."), arg);
        }
        strbuf_add(&(msg->buf), buf, len);
        free(buf);
@@@ -347,7 -351,7 +351,7 @@@ static struct notes_tree *init_notes_ch
        init_notes(NULL, NULL, NULL, 0);
        t = &default_notes_tree;
  
 -      if (prefixcmp(t->ref, "refs/notes/"))
 +      if (!starts_with(t->ref, "refs/notes/"))
                die("Refusing to %s notes in %s (outside of refs/notes/)",
                    subcommand, t->ref);
        return t;
@@@ -483,7 -487,7 +487,7 @@@ static int copy(int argc, const char **
        const char *rewrite_cmd = NULL;
        struct option options[] = {
                OPT__FORCE(&force, N_("replace existing notes")),
 -              OPT_BOOLEAN(0, "stdin", &from_stdin, N_("read objects from stdin")),
 +              OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")),
                OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"),
                           N_("load rewriting config for <command> (implies "
                              "--stdin)")),
@@@ -739,13 -743,13 +743,13 @@@ static int merge(int argc, const char *
                           N_("resolve notes conflicts using the given strategy "
                              "(manual/ours/theirs/union/cat_sort_uniq)")),
                OPT_GROUP(N_("Committing unmerged notes")),
 -              { OPTION_BOOLEAN, 0, "commit", &do_commit, NULL,
 +              { OPTION_SET_INT, 0, "commit", &do_commit, NULL,
                        N_("finalize notes merge by committing unmerged notes"),
 -                      PARSE_OPT_NOARG | PARSE_OPT_NONEG },
 +                      PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
                OPT_GROUP(N_("Aborting notes merge resolution")),
 -              { OPTION_BOOLEAN, 0, "abort", &do_abort, NULL,
 +              { OPTION_SET_INT, 0, "abort", &do_abort, NULL,
                        N_("abort notes merge"),
 -                      PARSE_OPT_NOARG | PARSE_OPT_NONEG },
 +                      PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
                OPT_END()
        };
  
@@@ -853,7 -857,7 +857,7 @@@ static int remove_cmd(int argc, const c
                OPT_BIT(0, "ignore-missing", &flag,
                        N_("attempt to remove non-existent note is not an error"),
                        IGNORE_MISSING),
 -              OPT_BOOLEAN(0, "stdin", &from_stdin,
 +              OPT_BOOL(0, "stdin", &from_stdin,
                            N_("read object names from the standard input")),
                OPT_END()
        };