Skip to content

Commit bc3c79a

Browse files
SRabbeliergitster
authored andcommitted
fast-import: add (non-)relative-marks feature
After specifying 'feature relative-marks' the paths specified with 'feature import-marks' and 'feature export-marks' are relative to an internal directory in the current repository. In git-fast-import this means that the paths are relative to the '.git/info/fast-import' directory. However, other importers may use a different location. Add 'feature non-relative-marks' to disable this behavior, this way it is possible to, for example, specify the import-marks location as relative, and the export-marks location as non-relative. Also add tests to verify this behavior. Cc: Daniel Barkalow <[email protected]> Signed-off-by: Sverre Rabbelier <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 081751c commit bc3c79a

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

Documentation/git-fast-import.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ OPTIONS
7575
set of marks. If a mark is defined to different values,
7676
the last file wins.
7777

78+
--relative-marks::
79+
After specifying --relative-marks= the paths specified
80+
with --import-marks= and --export-marks= are relative
81+
to an internal directory in the current repository.
82+
In git-fast-import this means that the paths are relative
83+
to the .git/info/fast-import directory. However, other
84+
importers may use a different location.
85+
86+
--no-relative-marks::
87+
Negates a previous --relative-marks. Allows for combining
88+
relative and non-relative marks by interweaving
89+
--(no-)-relative-marks= with the --(import|export)-marks=
90+
options.
91+
7892
--export-pack-edges=<file>::
7993
After creating a packfile, print a line of data to
8094
<file> listing the filename of the packfile and the last
@@ -875,6 +889,8 @@ The following features are currently supported:
875889
* date-format
876890
* import-marks
877891
* export-marks
892+
* relative-marks
893+
* no-relative-marks
878894
* force
879895

880896
The import-marks behaves differently from when it is specified as

fast-import.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ static struct mark_set *marks;
323323
static const char *export_marks_file;
324324
static const char *import_marks_file;
325325
static int import_marks_file_from_stream;
326+
static int relative_marks_paths;
326327

327328
/* Our last blob */
328329
static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
@@ -2470,6 +2471,16 @@ static void parse_progress(void)
24702471
skip_optional_lf();
24712472
}
24722473

2474+
static char* make_fast_import_path(const char *path)
2475+
{
2476+
struct strbuf abs_path = STRBUF_INIT;
2477+
2478+
if (!relative_marks_paths || is_absolute_path(path))
2479+
return xstrdup(path);
2480+
strbuf_addf(&abs_path, "%s/info/fast-import/%s", get_git_dir(), path);
2481+
return strbuf_detach(&abs_path, NULL);
2482+
}
2483+
24732484
static void option_import_marks(const char *marks, int from_stream)
24742485
{
24752486
if (import_marks_file) {
@@ -2481,7 +2492,7 @@ static void option_import_marks(const char *marks, int from_stream)
24812492
read_marks();
24822493
}
24832494

2484-
import_marks_file = xstrdup(marks);
2495+
import_marks_file = make_fast_import_path(marks);
24852496
import_marks_file_from_stream = from_stream;
24862497
}
24872498

@@ -2516,7 +2527,7 @@ static void option_active_branches(const char *branches)
25162527

25172528
static void option_export_marks(const char *marks)
25182529
{
2519-
export_marks_file = xstrdup(marks);
2530+
export_marks_file = make_fast_import_path(marks);
25202531
}
25212532

25222533
static void option_export_pack_edges(const char *edges)
@@ -2557,6 +2568,10 @@ static int parse_one_feature(const char *feature, int from_stream)
25572568
option_import_marks(feature + 13, from_stream);
25582569
} else if (!prefixcmp(feature, "export-marks=")) {
25592570
option_export_marks(feature + 13);
2571+
} else if (!prefixcmp(feature, "relative-marks")) {
2572+
relative_marks_paths = 1;
2573+
} else if (!prefixcmp(feature, "no-relative-marks")) {
2574+
relative_marks_paths = 0;
25602575
} else if (!prefixcmp(feature, "force")) {
25612576
force_update = 1;
25622577
} else {

t/t9300-fast-import.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,31 @@ test_expect_success 'R: multiple --import-marks= should be honoured' '
13461346
test_cmp marks.out combined.marks
13471347
'
13481348

1349+
cat >input <<EOF
1350+
feature relative-marks
1351+
feature import-marks=relative.in
1352+
feature export-marks=relative.out
1353+
EOF
1354+
1355+
test_expect_success 'R: feature relative-marks should be honoured' '
1356+
mkdir -p .git/info/fast-import/ &&
1357+
cp marks.new .git/info/fast-import/relative.in &&
1358+
git fast-import <input &&
1359+
test_cmp marks.new .git/info/fast-import/relative.out
1360+
'
1361+
1362+
cat >input <<EOF
1363+
feature relative-marks
1364+
feature import-marks=relative.in
1365+
feature no-relative-marks
1366+
feature export-marks=non-relative.out
1367+
EOF
1368+
1369+
test_expect_success 'R: feature no-relative-marks should be honoured' '
1370+
git fast-import <input &&
1371+
test_cmp marks.new non-relative.out
1372+
'
1373+
13491374
cat >input << EOF
13501375
option git quiet
13511376
blob

0 commit comments

Comments
 (0)