aboutsummaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-08-01 00:24:25 -0400
committerShawn O. Pearce <spearce@spearce.org>2007-08-19 03:38:35 -0400
commit2c570cde98cfde704ee67ea29031493c633f971e (patch)
tree01b2aab3fe8da779ecaed3baa7246d87f7ae0fa8 /fast-import.c
parent401d53fa35098266e2a4a904a4598b59f1b74663 (diff)
downloadgit-2c570cde98cfde704ee67ea29031493c633f971e.tar.gz
git-2c570cde98cfde704ee67ea29031493c633f971e.tar.xz
Make trailing LF following fast-import `data` commands optional
A few fast-import frontend developers have found it odd that we require the LF following a `data` command, especially in the exact byte count format. Technically we don't need this LF to parse the stream properly, but having it here does make the stream more readable to humans. We can easily make the LF optional by peeking at the next byte available from the stream and pushing it back into the buffer if its not LF. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/fast-import.c b/fast-import.c
index 98ebe4770..f950cff5e 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -61,7 +61,7 @@ Format of STDIN stream:
#
mark ::= 'mark' sp idnum lf;
data ::= (delimited_data | exact_data)
- lf;
+ lf?;
# note: delim may be any string but must not contain lf.
# data_line may contain any data but must not be exactly
@@ -1470,6 +1470,13 @@ static void read_next_command(void)
} while (!command_buf.eof && command_buf.buf[0] == '#');
}
+static void skip_optional_lf()
+{
+ int term_char = fgetc(stdin);
+ if (term_char != '\n' && term_char != EOF)
+ ungetc(term_char, stdin);
+}
+
static void cmd_mark(void)
{
if (!prefixcmp(command_buf.buf, "mark :")) {
@@ -1522,9 +1529,7 @@ static void *cmd_data (size_t *size)
}
}
- if (fgetc(stdin) != '\n')
- die("An lf did not trail the binary data as expected.");
-
+ skip_optional_lf();
*size = length;
return buffer;
}