archive: reorder option parsing and config reading
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index 5f497fac527362960560534b4285e69d4ed51176..61bedaed57216cadaf2716ef7aa0d63889571f8a 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -101,12 +101,12 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
                        if (end - p == p_len)
                                options->dirstat_permille = permille;
                        else {
-                               strbuf_addf(errmsg, "  Failed to parse dirstat cut-off percentage '%.*s'\n",
+                               strbuf_addf(errmsg, _("  Failed to parse dirstat cut-off percentage '%.*s'\n"),
                                            p_len, p);
                                ret++;
                        }
                } else {
-                       strbuf_addf(errmsg, "  Unknown dirstat parameter '%.*s'\n",
+                       strbuf_addf(errmsg, _("  Unknown dirstat parameter '%.*s'\n"),
                                    p_len, p);
                        ret++;
                }
@@ -202,7 +202,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
                struct strbuf errmsg = STRBUF_INIT;
                default_diff_options.dirstat_permille = diff_dirstat_permille_default;
                if (parse_dirstat_params(&default_diff_options, value, &errmsg))
-                       warning("Found errors in 'diff.dirstat' config variable:\n%s",
+                       warning(_("Found errors in 'diff.dirstat' config variable:\n%s"),
                                errmsg.buf);
                strbuf_release(&errmsg);
                diff_dirstat_permille_default = default_diff_options.dirstat_permille;
@@ -1117,8 +1117,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                        emit_line(ecbdata->opt, plain, reset, line, len);
                        fputs("~\n", ecbdata->opt->file);
                } else {
-                       /* don't print the prefix character */
-                       emit_line(ecbdata->opt, plain, reset, line+1, len-1);
+                       /*
+                        * Skip the prefix character, if any.  With
+                        * diff_suppress_blank_empty, there may be
+                        * none.
+                        */
+                       if (line[0] != '\n') {
+                             line++;
+                             len--;
+                       }
+                       emit_line(ecbdata->opt, plain, reset, line, len);
                }
                return;
        }
@@ -3260,7 +3268,7 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
 {
        struct strbuf errmsg = STRBUF_INIT;
        if (parse_dirstat_params(options, params, &errmsg))
-               die("Failed to parse --dirstat/-X option parameter:\n%s",
+               die(_("Failed to parse --dirstat/-X option parameter:\n%s"),
                    errmsg.buf);
        strbuf_release(&errmsg);
        /*
@@ -4448,6 +4456,13 @@ int diff_result_code(struct diff_options *opt, int status)
        return result;
 }
 
+int diff_can_quit_early(struct diff_options *opt)
+{
+       return (DIFF_OPT_TST(opt, QUICK) &&
+               !opt->filter &&
+               DIFF_OPT_TST(opt, HAS_CHANGES));
+}
+
 /*
  * Shall changes to this submodule be ignored?
  *
@@ -4549,20 +4564,20 @@ void diff_change(struct diff_options *options,
                DIFF_OPT_SET(options, HAS_CHANGES);
 }
 
-void diff_unmerge(struct diff_options *options,
-                 const char *path,
-                 unsigned mode, const unsigned char *sha1)
+struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)
 {
+       struct diff_filepair *pair;
        struct diff_filespec *one, *two;
 
        if (options->prefix &&
            strncmp(path, options->prefix, options->prefix_length))
-               return;
+               return NULL;
 
        one = alloc_filespec(path);
        two = alloc_filespec(path);
-       fill_filespec(one, sha1, mode);
-       diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
+       pair = diff_queue(&diff_queued_diff, one, two);
+       pair->is_unmerged = 1;
+       return pair;
 }
 
 static char *run_textconv(const char *pgm, struct diff_filespec *spec,