Merge branch 'jt/format-patch-base-info-above-sig'
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Sep 2016 22:15:27 +0000 (15:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Sep 2016 22:15:27 +0000 (15:15 -0700)
"git format-patch --base=..." feature that was recently added
showed the base commit information after "-- " e-mail signature
line, which turned out to be inconvenient. The base information
has been moved above the signature line.

* jt/format-patch-base-info-above-sig:
format-patch: show base info before email signature

1  2 
builtin/log.c
diff --combined builtin/log.c
index e6cab120182cfab3ac3af5d9a144959d0dc0bf05,cd9c4a46d10c0898ea84f9b5f5f4f833a1428dbd..b8cdf2b9d9cbd30950810eaa5dd5091dc23eb3c6
@@@ -464,9 -464,9 +464,9 @@@ static void show_tagger(char *buf, int 
        strbuf_release(&out);
  }
  
 -static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, const char *obj_name)
 +static int show_blob_object(const struct object_id *oid, struct rev_info *rev, const char *obj_name)
  {
 -      unsigned char sha1c[20];
 +      struct object_id oidc;
        struct object_context obj_context;
        char *buf;
        unsigned long size;
        fflush(rev->diffopt.file);
        if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
            !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
 -              return stream_blob_to_fd(1, sha1, NULL, 0);
 +              return stream_blob_to_fd(1, oid, NULL, 0);
  
 -      if (get_sha1_with_context(obj_name, 0, sha1c, &obj_context))
 +      if (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path[0] ||
 -          !textconv_object(obj_context.path, obj_context.mode, sha1c, 1, &buf, &size))
 -              return stream_blob_to_fd(1, sha1, NULL, 0);
 +          !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size))
 +              return stream_blob_to_fd(1, oid, NULL, 0);
  
        if (!buf)
                die(_("git show %s: bad file"), obj_name);
        return 0;
  }
  
 -static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
 +static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
  {
        unsigned long size;
        enum object_type type;
 -      char *buf = read_sha1_file(sha1, &type, &size);
 +      char *buf = read_sha1_file(oid->hash, &type, &size);
        int offset = 0;
  
        if (!buf)
 -              return error(_("Could not read object %s"), sha1_to_hex(sha1));
 +              return error(_("Could not read object %s"), oid_to_hex(oid));
  
        assert(type == OBJ_TAG);
        while (offset < size && buf[offset] != '\n') {
@@@ -574,7 -574,7 +574,7 @@@ int cmd_show(int argc, const char **arg
                const char *name = objects[i].name;
                switch (o->type) {
                case OBJ_BLOB:
 -                      ret = show_blob_object(o->oid.hash, &rev, name);
 +                      ret = show_blob_object(&o->oid, &rev, name);
                        break;
                case OBJ_TAG: {
                        struct tag *t = (struct tag *)o;
                                        diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        t->tag,
                                        diff_get_color_opt(&rev.diffopt, DIFF_RESET));
 -                      ret = show_tag_object(o->oid.hash, &rev);
 +                      ret = show_tag_object(&o->oid, &rev);
                        rev.shown_one = 1;
                        if (ret)
                                break;
@@@ -1042,7 -1042,6 +1042,6 @@@ static void make_cover_letter(struct re
        diff_flush(&opts);
  
        fprintf(rev->diffopt.file, "\n");
-       print_signature(rev->diffopt.file);
  }
  
  static const char *clean_message_id(const char *msg_id)
@@@ -1248,11 -1247,11 +1247,11 @@@ static struct commit *get_base_commit(c
                if (upstream) {
                        struct commit_list *base_list;
                        struct commit *commit;
 -                      unsigned char sha1[20];
 +                      struct object_id oid;
  
 -                      if (get_sha1(upstream, sha1))
 +                      if (get_oid(upstream, &oid))
                                die(_("Failed to resolve '%s' as a valid ref."), upstream);
 -                      commit = lookup_commit_or_die(sha1, "upstream base");
 +                      commit = lookup_commit_or_die(oid.hash, "upstream base");
                        base_list = get_merge_bases_many(commit, total, list);
                        /* There should be one and only one merge base. */
                        if (!base_list || base_list->next)
@@@ -1339,15 -1338,15 +1338,15 @@@ static void prepare_bases(struct base_t
         * and stuff them in bases structure.
         */
        while ((commit = get_revision(&revs)) != NULL) {
 -              unsigned char sha1[20];
 +              struct object_id oid;
                struct object_id *patch_id;
                if (commit->util)
                        continue;
 -              if (commit_patch_id(commit, &diffopt, sha1, 0))
 +              if (commit_patch_id(commit, &diffopt, oid.hash, 0))
                        die(_("cannot get patch id"));
                ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id);
                patch_id = bases->patch_id + bases->nr_patch_id;
 -              hashcpy(patch_id->hash, sha1);
 +              oidcpy(patch_id, &oid);
                bases->nr_patch_id++;
        }
  }
@@@ -1361,7 -1360,7 +1360,7 @@@ static void print_bases(struct base_tre
                return;
  
        /* Show the base commit */
-       fprintf(file, "base-commit: %s\n", oid_to_hex(&bases->base_commit));
+       fprintf(file, "\nbase-commit: %s\n", oid_to_hex(&bases->base_commit));
  
        /* Show the prerequisite patches */
        for (i = bases->nr_patch_id - 1; i >= 0; i--)
@@@ -1628,10 -1627,10 +1627,10 @@@ int cmd_format_patch(int argc, const ch
                        check_head = 1;
  
                if (check_head) {
 -                      unsigned char sha1[20];
 +                      struct object_id oid;
                        const char *ref, *v;
                        ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
 -                                               sha1, NULL);
 +                                               oid.hash, NULL);
                        if (ref && skip_prefix(ref, "refs/heads/", &v))
                                branch_name = xstrdup(v);
                        else
                /* nothing to do */
                return 0;
        total = nr;
 -      if (!keep_subject && auto_number && total > 1)
 -              numbered = 1;
 -      if (numbered)
 -              rev.total = total + start_number - 1;
        if (cover_letter == -1) {
                if (config_cover_letter == COVER_AUTO)
                        cover_letter = (total > 1);
                else
                        cover_letter = (config_cover_letter == COVER_ON);
        }
 +      if (!keep_subject && auto_number && (total > 1 || cover_letter))
 +              numbered = 1;
 +      if (numbered)
 +              rev.total = total + start_number - 1;
  
        if (!signature) {
                ; /* --no-signature inhibits all signatures */
                make_cover_letter(&rev, use_stdout,
                                  origin, nr, list, branch_name, quiet);
                print_bases(&bases, rev.diffopt.file);
+               print_signature(rev.diffopt.file);
                total++;
                start_number--;
        }
                if (!use_stdout)
                        rev.shown_one = 0;
                if (shown) {
+                       print_bases(&bases, rev.diffopt.file);
                        if (rev.mime_boundary)
                                fprintf(rev.diffopt.file, "\n--%s%s--\n\n\n",
                                       mime_boundary_leader,
                                       rev.mime_boundary);
                        else
                                print_signature(rev.diffopt.file);
-                       print_bases(&bases, rev.diffopt.file);
                }
                if (!use_stdout)
                        fclose(rev.diffopt.file);
  
  static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
  {
 -      unsigned char sha1[20];
 -      if (get_sha1(arg, sha1) == 0) {
 -              struct commit *commit = lookup_commit_reference(sha1);
 +      struct object_id oid;
 +      if (get_oid(arg, &oid) == 0) {
 +              struct commit *commit = lookup_commit_reference(oid.hash);
                if (commit) {
                        commit->object.flags |= flags;
                        add_pending_object(revs, &commit->object, arg);