From: Junio C Hamano Date: Thu, 30 Jun 2011 00:03:10 +0000 (-0700) Subject: Merge branch 'jk/combine-diff-binary-etc' X-Git-Tag: v1.7.7-rc0~126 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/dbae1a13363c45d3f77061f61ca73a0c3ed045cf?ds=inline;hp=-c Merge branch 'jk/combine-diff-binary-etc' * jk/combine-diff-binary-etc: combine-diff: respect textconv attributes refactor get_textconv to not require diff_filespec combine-diff: handle binary files as binary combine-diff: calculate mode_differs earlier combine-diff: split header printing into its own function --- dbae1a13363c45d3f77061f61ca73a0c3ed045cf diff --combined diff.c index 61bedaed57,3f538f5803..5dd9049c7d --- a/diff.c +++ b/diff.c @@@ -1117,16 -1117,8 +1117,16 @@@ static void fn_out_consume(void *priv, 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; } @@@ -1984,19 -1976,7 +1984,7 @@@ struct userdiff_driver *get_textconv(st return NULL; diff_filespec_load_driver(one); - if (!one->driver->textconv) - return NULL; - - if (one->driver->textconv_want_cache && !one->driver->textconv_cache) { - struct notes_cache *c = xmalloc(sizeof(*c)); - struct strbuf name = STRBUF_INIT; - - strbuf_addf(&name, "textconv/%s", one->driver->name); - notes_cache_init(c, name.buf, one->driver->textconv); - one->driver->textconv_cache = c; - } - - return one->driver; + return userdiff_get_textconv(one->driver); } static void builtin_diff(const char *name_a, @@@ -4456,13 -4436,6 +4444,13 @@@ int diff_result_code(struct diff_option 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? * diff --combined userdiff.c index e55310cd02,5d62e795a2..01d3a8b81e --- a/userdiff.c +++ b/userdiff.c @@@ -60,24 -60,10 +60,24 @@@ PATTERNS("pascal" "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+" "|<>|<=|>=|:=|\\.\\."), PATTERNS("perl", - "^[ \t]*package .*;\n" - "^[ \t]*sub .* \\{\n" - "^[A-Z]+ \\{\n" /* BEGIN, END, ... */ - "^=head[0-9] ", /* POD */ + "^package .*\n" + "^sub [[:alnum:]_':]+[ \t]*" + "(\\([^)]*\\)[ \t]*)?" /* prototype */ + /* + * Attributes. A regex can't count nested parentheses, + * so just slurp up whatever we see, taking care not + * to accept lines like "sub foo; # defined elsewhere". + * + * An attribute could contain a semicolon, but at that + * point it seems reasonable enough to give up. + */ + "(:[^;#]*)?" + "(\\{[ \t]*)?" /* brace can come here or on the next line */ + "(#.*)?$\n" /* comment */ + "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*" + "(\\{[ \t]*)?" /* brace can come here or on the next line */ + "(#.*)?$\n" + "^=head[0-9] .*", /* POD */ /* -- */ "[[:alpha:]_'][[:alnum:]_']*" "|0[xb]?[0-9a-fA-F_]*" @@@ -281,3 -267,20 +281,20 @@@ struct userdiff_driver *userdiff_find_b return NULL; return userdiff_find_by_name(check.value); } + + struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver) + { + if (!driver->textconv) + return NULL; + + if (driver->textconv_want_cache && !driver->textconv_cache) { + struct notes_cache *c = xmalloc(sizeof(*c)); + struct strbuf name = STRBUF_INIT; + + strbuf_addf(&name, "textconv/%s", driver->name); + notes_cache_init(c, name.buf, driver->textconv); + driver->textconv_cache = c; + } + + return driver; + }