Skip to content

Commit f963bd5

Browse files
SRabbeliergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07cd932 commit f963bd5

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

Documentation/git-fast-import.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ and control the current import process. More detailed discussion
303303
standard output. This command is optional and is not needed
304304
to perform an import.
305305

306+
`feature`::
307+
Require that fast-import supports the specified feature, or
308+
abort if it does not.
309+
306310
`commit`
307311
~~~~~~~~
308312
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
846850
inform the reader when the `checkpoint` has been completed and it
847851
can safely access the refs that fast-import updated.
848852

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+
849874
Crash Reports
850875
-------------
851876
If fast-import is supplied invalid input it will terminate with a

fast-import.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ static struct recent_command *rc_free;
353353
static unsigned int cmd_save = 100;
354354
static uintmax_t next_mark;
355355
static struct strbuf new_data = STRBUF_INIT;
356+
static int seen_data_command;
356357

357358
static void write_branch_report(FILE *rpt, struct branch *b)
358359
{
@@ -1704,6 +1705,11 @@ static int read_next_command(void)
17041705
if (stdin_eof)
17051706
return EOF;
17061707

1708+
if (!seen_data_command
1709+
&& prefixcmp(command_buf.buf, "feature ")) {
1710+
seen_data_command = 1;
1711+
}
1712+
17071713
rc = rc_free;
17081714
if (rc)
17091715
rc_free = rc->next;
@@ -2533,6 +2539,36 @@ static void parse_one_option(const char *option)
25332539
}
25342540
}
25352541

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+
25362572
static int git_pack_config(const char *k, const char *v, void *cb)
25372573
{
25382574
if (!strcmp(k, "pack.depth")) {
@@ -2612,6 +2648,8 @@ int main(int argc, const char **argv)
26122648
parse_checkpoint();
26132649
else if (!prefixcmp(command_buf.buf, "progress "))
26142650
parse_progress();
2651+
else if (!prefixcmp(command_buf.buf, "feature "))
2652+
parse_feature();
26152653
else
26162654
die("Unsupported command: %s", command_buf.buf);
26172655
}

t/t9300-fast-import.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,4 +1254,74 @@ test_expect_success \
12541254
'Q: verify note for third commit' \
12551255
'git cat-file blob refs/notes/foobar:$commit3 >actual && test_cmp expect actual'
12561256

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+
12571327
test_done

0 commit comments

Comments
 (0)