Move better_branch_name above get_ref in merge-recursive.
[gitweb.git] / commit.c
index df4bc0775a5042a353cb37228ff66210f35ed97b..eb06afbbe0f00ac4f553e37c50eca290418a7907 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "tag.h"
 #include "commit.h"
+#include "pkt-line.h"
 #include "utf8.h"
 
 int save_commit_buffer = 1;
@@ -222,6 +223,8 @@ static void prepare_commit_graft(void)
                return;
        graft_file = get_graft_file();
        read_graft_file(graft_file);
+       /* make sure shallows are read */
+       is_repository_shallow();
        commit_graft_prepared = 1;
 }
 
@@ -235,6 +238,37 @@ static struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
        return commit_graft[pos];
 }
 
+int write_shallow_commits(int fd, int use_pack_protocol)
+{
+       int i, count = 0;
+       for (i = 0; i < commit_graft_nr; i++)
+               if (commit_graft[i]->nr_parent < 0) {
+                       const char *hex =
+                               sha1_to_hex(commit_graft[i]->sha1);
+                       count++;
+                       if (use_pack_protocol)
+                               packet_write(fd, "shallow %s", hex);
+                       else {
+                               write(fd, hex,  40);
+                               write(fd, "\n", 1);
+                       }
+               }
+       return count;
+}
+
+int unregister_shallow(const unsigned char *sha1)
+{
+       int pos = commit_graft_pos(sha1);
+       if (pos < 0)
+               return -1;
+       if (pos + 1 < commit_graft_nr)
+               memcpy(commit_graft + pos, commit_graft + pos + 1,
+                               sizeof(struct commit_graft *)
+                               * (commit_graft_nr - pos - 1));
+       commit_graft_nr--;
+       return 0;
+}
+
 int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
 {
        char *tail = buffer;
@@ -592,12 +626,20 @@ static char *get_header(const struct commit *commit, const char *key)
 
 static char *logmsg_reencode(const struct commit *commit)
 {
-       char *encoding = get_header(commit, "encoding");
+       char *encoding;
        char *out;
+       char *output_encoding = (git_log_output_encoding
+                                ? git_log_output_encoding
+                                : git_commit_encoding);
 
-       if (!encoding || !strcmp(encoding, git_commit_encoding))
+       if (!output_encoding)
+               return NULL;
+       encoding = get_header(commit, "encoding");
+       if (!encoding || !strcmp(encoding, output_encoding)) {
+               free(encoding);
                return NULL;
-       out = reencode_string(commit->buffer, git_commit_encoding, encoding);
+       }
+       out = reencode_string(commit->buffer, output_encoding, encoding);
        free(encoding);
        if (!out)
                return NULL;
@@ -618,15 +660,10 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
        int parents_shown = 0;
        const char *msg = commit->buffer;
        int plain_non_ascii = 0;
-       char *reencoded = NULL;
+       char *reencoded = logmsg_reencode(commit);
 
-       if (*git_commit_encoding) {
-               reencoded = logmsg_reencode(commit);
-               if (reencoded) {
-                       msg = reencoded;
-                       len = strlen(msg);
-               }
-       }
+       if (reencoded)
+               msg = reencoded;
 
        if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
                indent = 0;
@@ -643,7 +680,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
                for (in_body = i = 0; (ch = msg[i]) && i < len; i++) {
                        if (!in_body) {
                                /* author could be non 7-bit ASCII but
-                                * the log may so; skip over the
+                                * the log may be so; skip over the
                                 * header part first.
                                 */
                                if (ch == '\n' &&
@@ -1064,3 +1101,20 @@ struct commit_list *get_merge_bases(struct commit *one,
        free(rslt);
        return result;
 }
+
+int in_merge_bases(struct commit *rev1, struct commit *rev2)
+{
+       struct commit_list *bases, *b;
+       int ret = 0;
+
+       bases = get_merge_bases(rev1, rev2, 1);
+       for (b = bases; b; b = b->next) {
+               if (!hashcmp(rev1->object.sha1, b->item->object.sha1)) {
+                       ret = 1;
+                       break;
+               }
+       }
+
+       free_commit_list(bases);
+       return ret;
+}