All of lore.kernel.org
 help / color / mirror / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH v2 4/8] fast-import: add support for new 'alias' command
Date: Mon, 30 Sep 2019 14:10:14 -0700	[thread overview]
Message-ID: <20190930211018.23633-5-newren@gmail.com> (raw)
In-Reply-To: <20190930211018.23633-1-newren@gmail.com>

fast-export and fast-import have nice --import-marks flags which allow
for incremental migrations.  However, if there is a mark in
fast-export's file of marks without a corresponding mark in the one for
fast-import, then we run the risk that fast-export tries to send new
objects relative to the mark it knows which fast-import does not,
causing fast-import to fail.

This arises in practice when there is a filter of some sort running
between the fast-export and fast-import processes which prunes some
commits programmatically.  Provide such a filter with the ability to
alias pruned commits to their most recent non-pruned ancestor.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/git-fast-import.txt | 22 +++++++++++
 fast-import.c                     | 62 ++++++++++++++++++++++++++-----
 t/t9300-fast-import.sh            |  5 +++
 3 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt
index 4977869465..a3f1e0c5e4 100644
--- a/Documentation/git-fast-import.txt
+++ b/Documentation/git-fast-import.txt
@@ -337,6 +337,13 @@ and control the current import process.  More detailed discussion
 	`commit` command.  This command is optional and is not
 	needed to perform an import.
 
+`alias`::
+	Record that a mark refers to a given object without first
+	creating any new object.  Using --import-marks and referring
+	to missing marks will cause fast-import to fail, so aliases
+	can provide a way to set otherwise pruned commits to a valid
+	value (e.g. the nearest non-pruned ancestor).
+
 `checkpoint`::
 	Forces fast-import to close the current packfile, generate its
 	unique SHA-1 checksum and index, and start a new packfile.
@@ -914,6 +921,21 @@ a data chunk which does not have an LF as its last byte.
 +
 The `LF` after `<delim> LF` is optional (it used to be required).
 
+`alias`
+~~~~~~~
+Record that a mark refers to a given object without first creating any
+new object.
+
+....
+	'alias' LF
+	mark
+	'to' SP <commit-ish> LF
+	LF?
+....
+
+For a detailed description of `<commit-ish>` see above under `from`.
+
+
 `checkpoint`
 ~~~~~~~~~~~~
 Forces fast-import to close the current packfile, start a new one, and to
diff --git a/fast-import.c b/fast-import.c
index 0042440487..9a12850d16 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2491,18 +2491,14 @@ static void parse_from_existing(struct branch *b)
 	}
 }
 
-static int parse_from(struct branch *b)
+static int parse_objectish(struct branch *b, const char *objectish)
 {
-	const char *from;
 	struct branch *s;
 	struct object_id oid;
 
-	if (!skip_prefix(command_buf.buf, "from ", &from))
-		return 0;
-
 	oidcpy(&oid, &b->branch_tree.versions[1].oid);
 
-	s = lookup_branch(from);
+	s = lookup_branch(objectish);
 	if (b == s)
 		die("Can't create a branch from itself: %s", b->name);
 	else if (s) {
@@ -2510,8 +2506,8 @@ static int parse_from(struct branch *b)
 		oidcpy(&b->oid, &s->oid);
 		oidcpy(&b->branch_tree.versions[0].oid, t);
 		oidcpy(&b->branch_tree.versions[1].oid, t);
-	} else if (*from == ':') {
-		uintmax_t idnum = parse_mark_ref_eol(from);
+	} else if (*objectish == ':') {
+		uintmax_t idnum = parse_mark_ref_eol(objectish);
 		struct object_entry *oe = find_mark(idnum);
 		if (oe->type != OBJ_COMMIT)
 			die("Mark :%" PRIuMAX " not a commit", idnum);
@@ -2525,13 +2521,13 @@ static int parse_from(struct branch *b)
 			} else
 				parse_from_existing(b);
 		}
-	} else if (!get_oid(from, &b->oid)) {
+	} else if (!get_oid(objectish, &b->oid)) {
 		parse_from_existing(b);
 		if (is_null_oid(&b->oid))
 			b->delete = 1;
 	}
 	else
-		die("Invalid ref name or SHA1 expression: %s", from);
+		die("Invalid ref name or SHA1 expression: %s", objectish);
 
 	if (b->branch_tree.tree && !oideq(&oid, &b->branch_tree.versions[1].oid)) {
 		release_tree_content_recursive(b->branch_tree.tree);
@@ -2542,6 +2538,26 @@ static int parse_from(struct branch *b)
 	return 1;
 }
 
+static int parse_from(struct branch *b)
+{
+	const char *from;
+
+	if (!skip_prefix(command_buf.buf, "from ", &from))
+		return 0;
+
+	return parse_objectish(b, from);
+}
+
+static int parse_objectish_with_prefix(struct branch *b, const char *prefix)
+{
+	const char *base;
+
+	if (!skip_prefix(command_buf.buf, prefix, &base))
+		return 0;
+
+	return parse_objectish(b, base);
+}
+
 static struct hash_list *parse_merge(unsigned int *count)
 {
 	struct hash_list *list = NULL, **tail = &list, *n;
@@ -3089,6 +3105,28 @@ static void parse_progress(void)
 	skip_optional_lf();
 }
 
+static void parse_alias(void)
+{
+	struct object_entry *e;
+	struct branch b;
+
+	skip_optional_lf();
+	read_next_command();
+
+	/* mark ... */
+	parse_mark();
+	if (!next_mark)
+		die(_("Expected 'mark' command, got %s"), command_buf.buf);
+
+	/* to ... */
+	memset(&b, 0, sizeof(b));
+	if (!parse_objectish_with_prefix(&b, "to "))
+		die(_("Expected 'to' command, got %s"), command_buf.buf);
+	e = find_object(&b.oid);
+	assert(e);
+	insert_mark(next_mark, e);
+}
+
 static char* make_fast_import_path(const char *path)
 {
 	if (!relative_marks_paths || is_absolute_path(path))
@@ -3216,6 +3254,8 @@ static int parse_one_feature(const char *feature, int from_stream)
 		option_import_marks(arg, from_stream, 1);
 	} else if (skip_prefix(feature, "export-marks=", &arg)) {
 		option_export_marks(arg);
+	} else if (!strcmp(feature, "alias")) {
+		; /* Don't die - this feature is supported */
 	} else if (!strcmp(feature, "get-mark")) {
 		; /* Don't die - this feature is supported */
 	} else if (!strcmp(feature, "cat-blob")) {
@@ -3372,6 +3412,8 @@ int cmd_main(int argc, const char **argv)
 			parse_checkpoint();
 		else if (!strcmp("done", command_buf.buf))
 			break;
+		else if (!strcmp("alias", command_buf.buf))
+			parse_alias();
 		else if (starts_with(command_buf.buf, "progress "))
 			parse_progress();
 		else if (skip_prefix(command_buf.buf, "feature ", &v))
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 3ad2b2f1ba..41f2a1dad9 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -111,6 +111,10 @@ test_expect_success 'A: create pack from stdin' '
 	Tag of tag of our lovely commit
 	EOF
 
+	alias
+	mark :8
+	to :5
+
 	INPUT_END
 	git fast-import --export-marks=marks.out <input &&
 	git whatchanged master
@@ -195,6 +199,7 @@ test_expect_success 'A: verify marks output' '
 	:5 $(git rev-parse --verify master^0)
 	:6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
 	:7 $(git rev-parse --verify nested)
+	:8 $(git rev-parse --verify master^0)
 	EOF
 	test_cmp expect marks.out
 '
-- 
2.23.0.264.gac739dbb79


  parent reply	other threads:[~2019-09-30 21:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25  1:39 [PATCH 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-09-25  1:39 ` [PATCH 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-09-25  1:39 ` [PATCH 2/8] fast-import: fix handling of deleted tags Elijah Newren
2019-09-25  1:40 ` [PATCH 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-09-25  1:40 ` [PATCH 4/8] fast-import: add support for new 'alias' command Elijah Newren
2019-09-25  1:40 ` [PATCH 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-09-25  1:40 ` [PATCH 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-09-25  1:40 ` [PATCH 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-09-25  1:40 ` [PATCH 8/8] fast-export: handle nested tags Elijah Newren
2019-09-30 21:10 ` [PATCH v2 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-09-30 21:10   ` [PATCH v2 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-09-30 21:10   ` [PATCH v2 2/8] fast-import: fix handling of deleted tags Elijah Newren
2019-10-03 11:53     ` René Scharfe
2019-09-30 21:10   ` [PATCH v2 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-09-30 21:10   ` Elijah Newren [this message]
2019-09-30 21:10   ` [PATCH v2 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-09-30 21:10   ` [PATCH v2 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-09-30 21:10   ` [PATCH v2 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-09-30 21:10   ` [PATCH v2 8/8] fast-export: handle nested tags Elijah Newren
2019-10-02 15:54   ` [PATCH v2 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-10-02 20:10     ` Junio C Hamano
2019-10-02 21:05       ` Elijah Newren
2019-10-03  1:07         ` Junio C Hamano
2019-10-03 20:27   ` [PATCH -v3 " Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 2/8] fast-import: fix handling of deleted tags Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 4/8] fast-import: add support for new 'alias' command Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 8/8] fast-export: handle nested tags Elijah Newren
2019-10-04  5:51     ` [PATCH -v3 0/8] fast export/import: handle nested tags, improve incremental exports Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190930211018.23633-5-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.