vcs-svn: Sharpen parsing of property lines
Prepare to add a new type of property line (the 'D' line) to handle property deltas. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Nov 19, 2010 at 18:54 UTC
6263c06d49abdf5e5defdf528c3ff67bf948ac9b
1 file changed
+19
-11
vcs-svn/svndump.c
+19
-11
@@ -134,21 +134,29 @@ static void handle_property(uint32_t key, const char *val, uint32_t len)
134
135
static void read_props(void)
136
{
137
- uint32_t len;
137
uint32_t key = ~0;
139
- char *val = NULL;
140
- char *t;
138
+ const char *t;
139
while ((t = buffer_read_line()) && strcmp(t, "PROPS-END")) {
142
- if (!strncmp(t, "K ", 2)) {
143
- len = atoi(&t[2]);
144
- key = pool_intern(buffer_read_string(len));
145
- buffer_read_line();
146
- } else if (!strncmp(t, "V ", 2)) {
147
- len = atoi(&t[2]);
148
- val = buffer_read_string(len);
140
+ uint32_t len;
141
+ const char *val;
142
+ const char type = t[0];
143
+
144
+ if (!type || t[1] != ' ')
145
+ die("invalid property line: %s\n", t);
146
+ len = atoi(&t[2]);
147
+ val = buffer_read_string(len);
148
+ buffer_skip_bytes(1); /* Discard trailing newline. */
149
+
150
+ switch (type) {
151
+ case 'K':
152
+ key = pool_intern(val);
153
+ continue;
154
+ case 'V':
155
handle_property(key, val, len);
156
key = ~0;
151
- buffer_read_line();
157
+ continue;
158
+ default:
159
+ die("invalid property line: %s\n", t);
160
}
161
}
162
}