gitweb: Add diff tree, with links to patches, to commitdiff view
[gitweb.git] / builtin-fmt-merge-msg.c
index 65274824d3b29aeb0ff78fc360c93820214c1ef8..76d22b47ba2906ecb59f0d8e279cf55a80bf8c86 100644 (file)
@@ -1,3 +1,4 @@
+#include "builtin.h"
 #include "cache.h"
 #include "commit.h"
 #include "diff.h"
@@ -7,7 +8,7 @@
 static const char *fmt_merge_msg_usage =
        "git-fmt-merge-msg [--summary] [--no-summary] [--file <file>]";
 
-static int merge_summary = 0;
+static int merge_summary;
 
 static int fmt_merge_msg_config(const char *key, const char *value)
 {
@@ -26,8 +27,8 @@ static void append_to_list(struct list *list, char *value, void *payload)
 {
        if (list->nr == list->alloc) {
                list->alloc += 32;
-               list->list = realloc(list->list, sizeof(char *) * list->alloc);
-               list->payload = realloc(list->payload,
+               list->list = xrealloc(list->list, sizeof(char *) * list->alloc);
+               list->payload = xrealloc(list->payload,
                                sizeof(char *) * list->alloc);
        }
        list->payload[list->nr] = payload;
@@ -54,8 +55,7 @@ static void free_list(struct list *list)
 
        for (i = 0; i < list->nr; i++) {
                free(list->list[i]);
-               if (list->payload[i])
-                       free(list->payload[i]);
+               free(list->payload[i]);
        }
        free(list->list);
        free(list->payload);
@@ -76,6 +76,7 @@ static int handle_line(char *line)
        unsigned char *sha1;
        char *src, *origin;
        struct src_data *src_data;
+       int pulling_head = 0;
 
        if (len < 43 || line[40] != '\t')
                return 1;
@@ -101,8 +102,11 @@ static int handle_line(char *line)
        if (src) {
                *src = 0;
                src += 4;
-       } else
-               src = "HEAD";
+               pulling_head = 0;
+       } else {
+               src = line;
+               pulling_head = 1;
+       }
 
        i = find_in_list(&srcs, src);
        if (i < 0) {
@@ -112,7 +116,10 @@ static int handle_line(char *line)
        }
        src_data = srcs.payload[i];
 
-       if (!strncmp(line, "branch ", 7)) {
+       if (pulling_head) {
+               origin = strdup(src);
+               src_data->head_status |= 1;
+       } else if (!strncmp(line, "branch ", 7)) {
                origin = strdup(line + 7);
                append_to_list(&src_data->branch, origin, NULL);
                src_data->head_status |= 2;
@@ -124,9 +131,6 @@ static int handle_line(char *line)
                origin = strdup(line + 14);
                append_to_list(&src_data->r_branch, origin, NULL);
                src_data->head_status |= 2;
-       } else if (!strcmp(line, "HEAD")) {
-               origin = strdup(src);
-               src_data->head_status |= 1;
        } else {
                origin = strdup(src);
                append_to_list(&src_data->generic, strdup(line), NULL);
@@ -177,7 +181,7 @@ static void shortlog(const char *name, unsigned char *sha1,
        int flags = UNINTERESTING | TREECHANGE | SEEN | SHOWN | ADDED;
 
        branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
-       if (!branch || branch->type != TYPE_COMMIT)
+       if (!branch || branch->type != OBJ_COMMIT)
                return;
 
        setup_revisions(0, NULL, rev, NULL);
@@ -238,7 +242,7 @@ static void shortlog(const char *name, unsigned char *sha1,
        free_list(&subjects);
 }
 
-int cmd_fmt_merge_msg(int argc, char **argv, char **envp)
+int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 {
        int limit = 20, i = 0;
        char line[1024];
@@ -338,7 +342,7 @@ int cmd_fmt_merge_msg(int argc, char **argv, char **envp)
                struct rev_info rev;
 
                head = lookup_commit(head_sha1);
-               init_revisions(&rev);
+               init_revisions(&rev, prefix);
                rev.commit_format = CMIT_FMT_ONELINE;
                rev.ignore_merges = 1;
                rev.limited = 1;