Merge branch 'rr/fi-import-marks-if-exists'
* rr/fi-import-marks-if-exists: fast-import: Introduce --import-marks-if-exists
This commit is contained in:
commit
fc180d98a2
@ -78,6 +78,10 @@ OPTIONS
|
|||||||
set of marks. If a mark is defined to different values,
|
set of marks. If a mark is defined to different values,
|
||||||
the last file wins.
|
the last file wins.
|
||||||
|
|
||||||
|
--import-marks-if-exists=<file>::
|
||||||
|
Like --import-marks but instead of erroring out, silently
|
||||||
|
skips the file if it does not exist.
|
||||||
|
|
||||||
--relative-marks::
|
--relative-marks::
|
||||||
After specifying --relative-marks= the paths specified
|
After specifying --relative-marks= the paths specified
|
||||||
with --import-marks= and --export-marks= are relative
|
with --import-marks= and --export-marks= are relative
|
||||||
|
@ -329,6 +329,7 @@ static struct mark_set *marks;
|
|||||||
static const char *export_marks_file;
|
static const char *export_marks_file;
|
||||||
static const char *import_marks_file;
|
static const char *import_marks_file;
|
||||||
static int import_marks_file_from_stream;
|
static int import_marks_file_from_stream;
|
||||||
|
static int import_marks_file_ignore_missing;
|
||||||
static int relative_marks_paths;
|
static int relative_marks_paths;
|
||||||
|
|
||||||
/* Our last blob */
|
/* Our last blob */
|
||||||
@ -1795,7 +1796,11 @@ static void read_marks(void)
|
|||||||
{
|
{
|
||||||
char line[512];
|
char line[512];
|
||||||
FILE *f = fopen(import_marks_file, "r");
|
FILE *f = fopen(import_marks_file, "r");
|
||||||
if (!f)
|
if (f)
|
||||||
|
;
|
||||||
|
else if (import_marks_file_ignore_missing && errno == ENOENT)
|
||||||
|
return; /* Marks file does not exist */
|
||||||
|
else
|
||||||
die_errno("cannot read '%s'", import_marks_file);
|
die_errno("cannot read '%s'", import_marks_file);
|
||||||
while (fgets(line, sizeof(line), f)) {
|
while (fgets(line, sizeof(line), f)) {
|
||||||
uintmax_t mark;
|
uintmax_t mark;
|
||||||
@ -2867,7 +2872,8 @@ static char* make_fast_import_path(const char *path)
|
|||||||
return strbuf_detach(&abs_path, NULL);
|
return strbuf_detach(&abs_path, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void option_import_marks(const char *marks, int from_stream)
|
static void option_import_marks(const char *marks,
|
||||||
|
int from_stream, int ignore_missing)
|
||||||
{
|
{
|
||||||
if (import_marks_file) {
|
if (import_marks_file) {
|
||||||
if (from_stream)
|
if (from_stream)
|
||||||
@ -2881,6 +2887,7 @@ static void option_import_marks(const char *marks, int from_stream)
|
|||||||
import_marks_file = make_fast_import_path(marks);
|
import_marks_file = make_fast_import_path(marks);
|
||||||
safe_create_leading_directories_const(import_marks_file);
|
safe_create_leading_directories_const(import_marks_file);
|
||||||
import_marks_file_from_stream = from_stream;
|
import_marks_file_from_stream = from_stream;
|
||||||
|
import_marks_file_ignore_missing = ignore_missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void option_date_format(const char *fmt)
|
static void option_date_format(const char *fmt)
|
||||||
@ -2980,7 +2987,10 @@ static int parse_one_feature(const char *feature, int from_stream)
|
|||||||
if (!prefixcmp(feature, "date-format=")) {
|
if (!prefixcmp(feature, "date-format=")) {
|
||||||
option_date_format(feature + 12);
|
option_date_format(feature + 12);
|
||||||
} else if (!prefixcmp(feature, "import-marks=")) {
|
} else if (!prefixcmp(feature, "import-marks=")) {
|
||||||
option_import_marks(feature + 13, from_stream);
|
option_import_marks(feature + 13, from_stream, 0);
|
||||||
|
} else if (!prefixcmp(feature, "import-marks-if-exists=")) {
|
||||||
|
option_import_marks(feature + strlen("import-marks-if-exists="),
|
||||||
|
from_stream, 1);
|
||||||
} else if (!prefixcmp(feature, "export-marks=")) {
|
} else if (!prefixcmp(feature, "export-marks=")) {
|
||||||
option_export_marks(feature + 13);
|
option_export_marks(feature + 13);
|
||||||
} else if (!strcmp(feature, "cat-blob")) {
|
} else if (!strcmp(feature, "cat-blob")) {
|
||||||
|
@ -1748,6 +1748,61 @@ test_expect_success \
|
|||||||
'cat input | git fast-import --export-marks=other.marks &&
|
'cat input | git fast-import --export-marks=other.marks &&
|
||||||
grep :1 other.marks'
|
grep :1 other.marks'
|
||||||
|
|
||||||
|
test_expect_success 'R: catch typo in marks file name' '
|
||||||
|
test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
|
||||||
|
echo "feature import-marks=nonexistent.marks" |
|
||||||
|
test_must_fail git fast-import
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'R: import and output marks can be the same file' '
|
||||||
|
rm -f io.marks &&
|
||||||
|
blob=$(echo hi | git hash-object --stdin) &&
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
:1 $blob
|
||||||
|
:2 $blob
|
||||||
|
EOF
|
||||||
|
git fast-import --export-marks=io.marks <<-\EOF &&
|
||||||
|
blob
|
||||||
|
mark :1
|
||||||
|
data 3
|
||||||
|
hi
|
||||||
|
|
||||||
|
EOF
|
||||||
|
git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
|
||||||
|
blob
|
||||||
|
mark :2
|
||||||
|
data 3
|
||||||
|
hi
|
||||||
|
|
||||||
|
EOF
|
||||||
|
test_cmp expect io.marks
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
|
||||||
|
rm -f io.marks &&
|
||||||
|
test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
|
||||||
|
blob
|
||||||
|
mark :1
|
||||||
|
data 3
|
||||||
|
hi
|
||||||
|
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'R: --import-marks-if-exists' '
|
||||||
|
rm -f io.marks &&
|
||||||
|
blob=$(echo hi | git hash-object --stdin) &&
|
||||||
|
echo ":1 $blob" >expect &&
|
||||||
|
git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
|
||||||
|
blob
|
||||||
|
mark :1
|
||||||
|
data 3
|
||||||
|
hi
|
||||||
|
|
||||||
|
EOF
|
||||||
|
test_cmp expect io.marks
|
||||||
|
'
|
||||||
|
|
||||||
cat >input << EOF
|
cat >input << EOF
|
||||||
feature import-marks=marks.out
|
feature import-marks=marks.out
|
||||||
feature export-marks=marks.new
|
feature export-marks=marks.new
|
||||||
|
Loading…
Reference in New Issue
Block a user