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 <barkalow@iabervon.org> 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:07 UTC
bc3c79aefc9cdb1127e1dfd22ad19cf6c6e94f09
3 files changed
+58
-2
Documentation/git-fast-import.txt
+16
@@ -75,6 +75,20 @@ OPTIONS
75
set of marks. If a mark is defined to different values,
76
the last file wins.
77
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
+
92
--export-pack-edges=<file>::
93
After creating a packfile, print a line of data to
94
<file> listing the filename of the packfile and the last
@@ -875,6 +889,8 @@ The following features are currently supported:
889
* date-format
890
* import-marks
891
* export-marks
892
+* relative-marks
893
+* no-relative-marks
894
* force
895
896
The import-marks behaves differently from when it is specified as
fast-import.c
+17
-2
@@ -323,6 +323,7 @@ static struct mark_set *marks;
323
static const char *export_marks_file;
324
static const char *import_marks_file;
325
static int import_marks_file_from_stream;
326
+static int relative_marks_paths;
327
328
/* Our last blob */
329
static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
@@ -2470,6 +2471,16 @@ static void parse_progress(void)
2471
skip_optional_lf();
2472
}
2473
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
+
2484
static void option_import_marks(const char *marks, int from_stream)
2485
{
2486
if (import_marks_file) {
@@ -2481,7 +2492,7 @@ static void option_import_marks(const char *marks, int from_stream)
2492
read_marks();
2493
}
2494
2484
- import_marks_file = xstrdup(marks);
2495
+ import_marks_file = make_fast_import_path(marks);
2496
import_marks_file_from_stream = from_stream;
2497
}
2498
@@ -2516,7 +2527,7 @@ static void option_active_branches(const char *branches)
2527
2528
static void option_export_marks(const char *marks)
2529
{
2519
- export_marks_file = xstrdup(marks);
2530
+ export_marks_file = make_fast_import_path(marks);
2531
}
2532
2533
static void option_export_pack_edges(const char *edges)
@@ -2557,6 +2568,10 @@ static int parse_one_feature(const char *feature, int from_stream)
2568
option_import_marks(feature + 13, from_stream);
2569
} else if (!prefixcmp(feature, "export-marks=")) {
2570
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;
2575
} else if (!prefixcmp(feature, "force")) {
2576
force_update = 1;
2577
} else {
t/t9300-fast-import.sh
+25
@@ -1346,6 +1346,31 @@ test_expect_success 'R: multiple --import-marks= should be honoured' '
1346
test_cmp marks.out combined.marks
1347
'
1348
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
+
1374
cat >input << EOF
1375
option git quiet
1376
blob