aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-09-14 18:44:01 -0700
committerJunio C Hamano <gitster@pobox.com>2009-09-15 02:40:51 -0700
commit250f79930d84af54dce15320914ea911d58dd8ca (patch)
treefa0b7e7375aaea6c5fe2d98f4d85c2fdd1c716ff
parent6957eb9a39cc765862e125edeef0dd70f359cff1 (diff)
downloadgit-250f79930d84af54dce15320914ea911d58dd8ca.tar.gz
git-250f79930d84af54dce15320914ea911d58dd8ca.tar.xz
diff.c: split emit_line() from the first char and the rest of the line
A new helper function emit_line_0() takes the first line of diff output (typically "-", " ", or "+") separately from the remainder of the line. No other functional changes. This change will make it easier to reuse the logic when emitting the rewrite diff, as we do not want to copy a line only to add "+"/"-"/" " immediately before its first character when we produce rewrite diff output. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--diff.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/diff.c b/diff.c
index 75489665b..e4aaebf0d 100644
--- a/diff.c
+++ b/diff.c
@@ -377,18 +377,31 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
ecbdata->blank_at_eof_in_postimage = (at - l2) + 1;
}
-static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
+static void emit_line_0(FILE *file, const char *set, const char *reset,
+ int first, const char *line, int len)
{
int has_trailing_newline, has_trailing_carriage_return;
+ int nofirst;
- has_trailing_newline = (len > 0 && line[len-1] == '\n');
- if (has_trailing_newline)
- len--;
- has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
- if (has_trailing_carriage_return)
- len--;
+ if (len == 0) {
+ has_trailing_newline = (first == '\n');
+ has_trailing_carriage_return = (!has_trailing_newline &&
+ (first == '\r'));
+ nofirst = has_trailing_newline || has_trailing_carriage_return;
+ } else {
+ has_trailing_newline = (len > 0 && line[len-1] == '\n');
+ if (has_trailing_newline)
+ len--;
+ has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
+ if (has_trailing_carriage_return)
+ len--;
+ nofirst = 0;
+ }
fputs(set, file);
+
+ if (!nofirst)
+ fputc(first, file);
fwrite(line, len, 1, file);
fputs(reset, file);
if (has_trailing_carriage_return)
@@ -397,6 +410,12 @@ static void emit_line(FILE *file, const char *set, const char *reset, const char
fputc('\n', file);
}
+static void emit_line(FILE *file, const char *set, const char *reset,
+ const char *line, int len)
+{
+ emit_line_0(file, set, reset, line[0], line+1, len-1);
+}
+
static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line, int len)
{
if (!((ecbdata->ws_rule & WS_BLANK_AT_EOF) &&