@matheusbsbs / matheus-bagliano / commits / f963bd5d71
Fork 0

fast-import: add feature command

This allows the fronted to require a specific feature to be supported by the backend, or abort. Also add support for four initial feature, date-format=, force=, import-marks=, export-marks=. Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sverre Rabbelier committed Dec 4, 2009 at 18:06 UTC f963bd5d71fd0db01f2c7f6f05df5a5f1af11b82
3 files changed +133
Documentation/git-fast-import.txt
+25
@@ -303,6 +303,10 @@ and control the current import process. More detailed discussion
303 standard output. This command is optional and is not needed
304 to perform an import.
305
306 +`feature`::
307 + Require that fast-import supports the specified feature, or
308 + abort if it does not.
309 +
310 `commit`
311 ~~~~~~~~
312 Create or update a branch with a new commit, recording one logical
@@ -846,6 +850,27 @@ Placing a `progress` command immediately after a `checkpoint` will
850 inform the reader when the `checkpoint` has been completed and it
851 can safely access the refs that fast-import updated.
852
853 +`feature`
854 +~~~~~~~~~
855 +Require that fast-import supports the specified feature, or abort if
856 +it does not.
857 +
858 +....
859 + 'feature' SP <feature> LF
860 +....
861 +
862 +The <feature> part of the command may be any string matching
863 +^[a-zA-Z][a-zA-Z-]*$ and should be understood by fast-import.
864 +
865 +Feature work identical as their option counterparts.
866 +
867 +The following features are currently supported:
868 +
869 +* date-format
870 +* import-marks
871 +* export-marks
872 +* force
873 +
874 Crash Reports
875 -------------
876 If fast-import is supplied invalid input it will terminate with a
fast-import.c
+38
@@ -353,6 +353,7 @@ static struct recent_command *rc_free;
353 static unsigned int cmd_save = 100;
354 static uintmax_t next_mark;
355 static struct strbuf new_data = STRBUF_INIT;
356 +static int seen_data_command;
357
358 static void write_branch_report(FILE *rpt, struct branch *b)
359 {
@@ -1704,6 +1705,11 @@ static int read_next_command(void)
1705 if (stdin_eof)
1706 return EOF;
1707
1708 + if (!seen_data_command
1709 + && prefixcmp(command_buf.buf, "feature ")) {
1710 + seen_data_command = 1;
1711 + }
1712 +
1713 rc = rc_free;
1714 if (rc)
1715 rc_free = rc->next;
@@ -2533,6 +2539,36 @@ static void parse_one_option(const char *option)
2539 }
2540 }
2541
2542 +static int parse_one_feature(const char *feature)
2543 +{
2544 + if (!prefixcmp(feature, "date-format=")) {
2545 + option_date_format(feature + 12);
2546 + } else if (!prefixcmp(feature, "import-marks=")) {
2547 + option_import_marks(feature + 13);
2548 + } else if (!prefixcmp(feature, "export-marks=")) {
2549 + option_export_marks(feature + 13);
2550 + } else if (!prefixcmp(feature, "force")) {
2551 + force_update = 1;
2552 + } else {
2553 + return 0;
2554 + }
2555 +
2556 + return 1;
2557 +}
2558 +
2559 +static void parse_feature(void)
2560 +{
2561 + char *feature = command_buf.buf + 8;
2562 +
2563 + if (seen_data_command)
2564 + die("Got feature command '%s' after data command", feature);
2565 +
2566 + if (parse_one_feature(feature))
2567 + return;
2568 +
2569 + die("This version of fast-import does not support feature %s.", feature);
2570 +}
2571 +
2572 static int git_pack_config(const char *k, const char *v, void *cb)
2573 {
2574 if (!strcmp(k, "pack.depth")) {
@@ -2612,6 +2648,8 @@ int main(int argc, const char **argv)
2648 parse_checkpoint();
2649 else if (!prefixcmp(command_buf.buf, "progress "))
2650 parse_progress();
2651 + else if (!prefixcmp(command_buf.buf, "feature "))
2652 + parse_feature();
2653 else
2654 die("Unsupported command: %s", command_buf.buf);
2655 }
t/t9300-fast-import.sh
+70
@@ -1254,4 +1254,74 @@ test_expect_success \
1254 'Q: verify note for third commit' \
1255 'git cat-file blob refs/notes/foobar:$commit3 >actual && test_cmp expect actual'
1256
1257 +###
1258 +### series R (feature)
1259 +###
1260 +
1261 +cat >input <<EOF
1262 +feature no-such-feature-exists
1263 +EOF
1264 +
1265 +test_expect_success 'R: abort on unsupported feature' '
1266 + test_must_fail git fast-import <input
1267 +'
1268 +
1269 +cat >input <<EOF
1270 +feature date-format=now
1271 +EOF
1272 +
1273 +test_expect_success 'R: supported feature is accepted' '
1274 + git fast-import <input
1275 +'
1276 +
1277 +cat >input << EOF
1278 +blob
1279 +data 3
1280 +hi
1281 +feature date-format=now
1282 +EOF
1283 +
1284 +test_expect_success 'R: abort on receiving feature after data command' '
1285 + test_must_fail git fast-import <input
1286 +'
1287 +
1288 +cat >input << EOF
1289 +feature export-marks=git.marks
1290 +blob
1291 +mark :1
1292 +data 3
1293 +hi
1294 +
1295 +EOF
1296 +
1297 +test_expect_success \
1298 + 'R: export-marks feature results in a marks file being created' \
1299 + 'cat input | git fast-import &&
1300 + grep :1 git.marks'
1301 +
1302 +test_expect_success \
1303 + 'R: export-marks options can be overriden by commandline options' \
1304 + 'cat input | git fast-import --export-marks=other.marks &&
1305 + grep :1 other.marks'
1306 +
1307 +cat >input << EOF
1308 +feature import-marks=marks.out
1309 +feature export-marks=marks.new
1310 +EOF
1311 +
1312 +test_expect_success \
1313 + 'R: import to output marks works without any content' \
1314 + 'cat input | git fast-import &&
1315 + test_cmp marks.out marks.new'
1316 +
1317 +cat >input <<EOF
1318 +feature import-marks=nonexistant.marks
1319 +feature export-marks=marks.new
1320 +EOF
1321 +
1322 +test_expect_success \
1323 + 'R: import marks prefers commandline marks file over the stream' \
1324 + 'cat input | git fast-import --import-marks=marks.out &&
1325 + test_cmp marks.out marks.new'
1326 +
1327 test_done