]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/log.c
notes: break set_display_notes() into smaller functions
[thirdparty/git.git] / builtin / log.c
index e63c8c2958276d17793ecc0cb15ed8945ee6caf6..b6d43a4a47ebbc39e36c5552b3bd0fdc5ae44404 100644 (file)
@@ -202,7 +202,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
        if (!rev->show_notes_given && (!rev->pretty_given || w.notes))
                rev->show_notes = 1;
        if (rev->show_notes)
-               init_display_notes(&rev->notes_opt);
+               load_display_notes(&rev->notes_opt);
 
        if ((rev->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) ||
            rev->diffopt.filter || rev->diffopt.flags.follow_renames)
@@ -251,7 +251,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
  * This gives a rough estimate for how many commits we
  * will print out in the list.
  */
-static int estimate_commit_count(struct rev_info *rev, struct commit_list *list)
+static int estimate_commit_count(struct commit_list *list)
 {
        int n = 0;
 
@@ -289,7 +289,7 @@ static void log_show_early(struct rev_info *revs, struct commit_list *list)
                switch (simplify_commit(revs, commit)) {
                case commit_show:
                        if (show_header) {
-                               int n = estimate_commit_count(revs, list);
+                               int n = estimate_commit_count(list);
                                show_early_header(revs, "incomplete", n);
                                show_header = 0;
                        }
@@ -333,7 +333,7 @@ static void early_output(int signal)
        show_early_output = log_show_early;
 }
 
-static void setup_early_output(struct rev_info *rev)
+static void setup_early_output(void)
 {
        struct sigaction sa;
 
@@ -364,7 +364,7 @@ static void setup_early_output(struct rev_info *rev)
 
 static void finish_early_output(struct rev_info *rev)
 {
-       int n = estimate_commit_count(rev, rev->commits);
+       int n = estimate_commit_count(rev->commits);
        signal(SIGALRM, SIG_IGN);
        show_early_header(rev, "done", n);
 }
@@ -376,7 +376,7 @@ static int cmd_log_walk(struct rev_info *rev)
        int saved_dcctc = 0, close_file = rev->diffopt.close_file;
 
        if (rev->early_output)
-               setup_early_output(rev);
+               setup_early_output();
 
        if (prepare_revision_walk(rev))
                die(_("revision walk setup failed"));
@@ -490,7 +490,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
        return cmd_log_walk(&rev);
 }
 
-static void show_tagger(char *buf, int len, struct rev_info *rev)
+static void show_tagger(const char *buf, struct rev_info *rev)
 {
        struct strbuf out = STRBUF_INIT;
        struct pretty_print_context pp = {0};
@@ -546,11 +546,11 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
        assert(type == OBJ_TAG);
        while (offset < size && buf[offset] != '\n') {
                int new_offset = offset + 1;
+               const char *ident;
                while (new_offset < size && buf[new_offset++] != '\n')
                        ; /* do nothing */
-               if (starts_with(buf + offset, "tagger "))
-                       show_tagger(buf + offset + 7,
-                                   new_offset - offset - 7, rev);
+               if (skip_prefix(buf + offset, "tagger ", &ident))
+                       show_tagger(ident, rev);
                offset = new_offset;
        }
 
@@ -769,6 +769,8 @@ static const char *signature = git_version_string;
 static const char *signature_file;
 static int config_cover_letter;
 static const char *config_output_directory;
+static int show_notes;
+static struct display_notes_opt notes_opt;
 
 enum {
        COVER_UNSET,
@@ -864,6 +866,16 @@ static int git_format_config(const char *var, const char *value, void *cb)
                        from = NULL;
                return 0;
        }
+       if (!strcmp(var, "format.notes")) {
+               int b = git_parse_maybe_bool(value);
+               if (b < 0)
+                       enable_ref_display_notes(&notes_opt, &show_notes, value);
+               else if (b)
+                       enable_default_display_notes(&notes_opt, &show_notes);
+               else
+                       disable_display_notes(&notes_opt, &show_notes);
+               return 0;
+       }
 
        return git_log_config(var, value, cb);
 }
@@ -1617,8 +1629,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        extra_to.strdup_strings = 1;
        extra_cc.strdup_strings = 1;
        init_log_defaults();
+       init_display_notes(&notes_opt);
        git_config(git_format_config, NULL);
        repo_init_revisions(the_repository, &rev, prefix);
+       rev.show_notes = show_notes;
+       memcpy(&rev.notes_opt, &notes_opt, sizeof(notes_opt));
        rev.commit_format = CMIT_FMT_EMAIL;
        rev.expand_tabs_in_log_default = 0;
        rev.verbose_header = 1;
@@ -1731,7 +1746,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                rev.diffopt.flags.binary = 1;
 
        if (rev.show_notes)
-               init_display_notes(&rev.notes_opt);
+               load_display_notes(&rev.notes_opt);
 
        if (!output_directory && !use_stdout)
                output_directory = config_output_directory;