Merge branch 'jk/read-commit-buffer-data-after-free'
authorJunio C Hamano <gitster@pobox.com>
Mon, 4 Feb 2013 18:25:18 +0000 (10:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 4 Feb 2013 18:25:18 +0000 (10:25 -0800)
Clarify the ownership rule for commit->buffer field, which some
callers incorrectly accessed without making sure it is populated.

* jk/read-commit-buffer-data-after-free:
logmsg_reencode: lazily load missing commit buffers
logmsg_reencode: never return NULL
commit: drop useless xstrdup of commit message

1  2 
builtin/commit.c
commit.h
diff --combined builtin/commit.c
index 6c95fa76d8e4f5a4bb7aaa69721c00034eba8632,6169f1e2dc2d974aefd33f021f2a6183e4d5db0e..1a0e5f14a36975a012199f9e7a96d9a58ee986d0
@@@ -733,15 -733,15 +733,15 @@@ static int prepare_to_commit(const cha
                if (cleanup_mode == CLEANUP_ALL)
                        status_printf(s, GIT_COLOR_NORMAL,
                                _("Please enter the commit message for your changes."
 -                              " Lines starting\nwith '#' will be ignored, and an empty"
 -                              " message aborts the commit.\n"));
 +                                " Lines starting\nwith '%c' will be ignored, and an empty"
 +                                " message aborts the commit.\n"), comment_line_char);
                else /* CLEANUP_SPACE, that is. */
                        status_printf(s, GIT_COLOR_NORMAL,
                                _("Please enter the commit message for your changes."
 -                              " Lines starting\n"
 -                              "with '#' will be kept; you may remove them"
 -                              " yourself if you want to.\n"
 -                              "An empty message aborts the commit.\n"));
 +                                " Lines starting\n"
 +                                "with '%c' will be kept; you may remove them"
 +                                " yourself if you want to.\n"
 +                                "An empty message aborts the commit.\n"), comment_line_char);
                if (only_include_assumed)
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                                        "%s", only_include_assumed);
@@@ -946,24 -946,14 +946,14 @@@ static void handle_untracked_files_arg(
  
  static const char *read_commit_message(const char *name)
  {
-       const char *out_enc, *out;
+       const char *out_enc;
        struct commit *commit;
  
        commit = lookup_commit_reference_by_name(name);
        if (!commit)
                die(_("could not lookup commit %s"), name);
        out_enc = get_commit_output_encoding();
-       out = logmsg_reencode(commit, out_enc);
-       /*
-        * If we failed to reencode the buffer, just copy it
-        * byte for byte so the user can try to fix it up.
-        * This also handles the case where input and output
-        * encodings are identical.
-        */
-       if (out == NULL)
-               out = xstrdup(commit->buffer);
-       return out;
+       return logmsg_reencode(commit, out_enc);
  }
  
  static int parse_and_validate_options(int argc, const char *argv[],
diff --combined commit.h
index 95b8350a5b5109bf2d8a1e60fa4d8065501a031d,e770649731d1fd7fde3dd02cffbb8f9cee734c6a..4138bb4c0850f95ba7215cb62f457cd682495968
+++ b/commit.h
@@@ -101,6 -101,7 +101,7 @@@ extern int has_non_ascii(const char *te
  struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
  extern char *logmsg_reencode(const struct commit *commit,
                             const char *output_encoding);
+ extern void logmsg_free(char *msg, const struct commit *commit);
  extern void get_commit_format(const char *arg, struct rev_info *);
  extern const char *format_subject(struct strbuf *sb, const char *msg,
                                  const char *line_separator);
@@@ -163,9 -164,6 +164,9 @@@ extern struct commit_list *get_merge_ba
  extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
  extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
  
 +/* largest postive number a signed 32-bit integer can contain */
 +#define INFINITE_DEPTH 0x7fffffff
 +
  extern int register_shallow(const unsigned char *sha1);
  extern int unregister_shallow(const unsigned char *sha1);
  extern int for_each_commit_graft(each_commit_graft_fn, void *);