clean.c: use designated initializer
[gitweb.git] / builtin / log.c
index a440601efe826aadabdffbfd0d461f83047b8e99..c6362cf92ed799696128a5da6c802813db62fbcf 100644 (file)
@@ -5,6 +5,7 @@
  *              2006 Junio Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "color.h"
 #include "commit.h"
@@ -483,16 +484,20 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
            !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
                return stream_blob_to_fd(1, oid, NULL, 0);
 
-       if (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))
+       if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
+                                 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, &oidc, 1, &buf, &size))
+       if (!obj_context.path ||
+           !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
+               free(obj_context.path);
                return stream_blob_to_fd(1, oid, NULL, 0);
+       }
 
        if (!buf)
                die(_("git show %s: bad file"), obj_name);
 
        write_or_die(1, buf, size);
+       free(obj_context.path);
        return 0;
 }
 
@@ -842,8 +847,10 @@ static int open_next_file(struct commit *commit, const char *subject,
        if (output_directory) {
                strbuf_addstr(&filename, output_directory);
                if (filename.len >=
-                   PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
+                   PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) {
+                       strbuf_release(&filename);
                        return error(_("name of output directory is too long"));
+               }
                strbuf_complete(&filename, '/');
        }
 
@@ -857,8 +864,11 @@ static int open_next_file(struct commit *commit, const char *subject,
        if (!quiet)
                printf("%s\n", filename.buf + outdir_offset);
 
-       if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL)
-               return error(_("Cannot open patch file %s"), filename.buf);
+       if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) {
+               error_errno(_("Cannot open patch file %s"), filename.buf);
+               strbuf_release(&filename);
+               return -1;
+       }
 
        strbuf_release(&filename);
        return 0;
@@ -1043,9 +1053,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 
        diff_setup_done(&opts);
 
-       diff_tree_sha1(origin->tree->object.oid.hash,
-                      head->tree->object.oid.hash,
-                      "", &opts);
+       diff_tree_oid(&origin->tree->object.oid,
+                     &head->tree->object.oid,
+                     "", &opts);
        diffcore_std(&opts);
        diff_flush(&opts);
 
@@ -1298,7 +1308,7 @@ static struct commit *get_base_commit(const char *base_commit,
 
                if (rev_nr % 2)
                        rev[i] = rev[2 * i];
-               rev_nr = (rev_nr + 1) / 2;
+               rev_nr = DIV_ROUND_UP(rev_nr, 2);
        }
 
        if (!in_merge_bases(base, rev[0]))
@@ -1354,7 +1364,7 @@ static void prepare_bases(struct base_tree_info *bases,
                struct object_id *patch_id;
                if (commit->util)
                        continue;
-               if (commit_patch_id(commit, &diffopt, oid.hash, 0))
+               if (commit_patch_id(commit, &diffopt, &oid, 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;