Commit a16d97bdc65b49050d622450d50642fa98eb3cc1

Stefan Sperling 2021-09-02T19:19:49

remove ancestry sanity checks from 'got cherrypick' and 'got backout' While these checks might catch usage mistakes the performance overhead of scanning the entire history of the current branch is not worth it. Measurements provided by naddy, cherrypicking 5 commits of OpenBSD's src repository in usr.bin/rsync: Before: 5m50.33s real 4m02.36s user 2m04.41s system After: 1m04.92s real 0m28.24s user 0m36.54s system Further performance improvements could be needed but this is a first step.

diff --git a/got/got.1 b/got/got.1
index 02e13d5..15441d5 100644
--- a/got/got.1
+++ b/got/got.1
@@ -1582,7 +1582,7 @@ Merge changes from a single
 into the work tree.
 The specified
 .Ar commit
-must be on a different branch than the work tree's base commit.
+should be on a different branch than the work tree's base commit.
 The expected argument is a reference or a commit ID SHA1 hash.
 An abbreviated hash argument will be expanded to a full SHA1 hash
 automatically, provided the abbreviation is unique.
@@ -1626,7 +1626,7 @@ Reverse-merge changes from a single
 into the work tree.
 The specified
 .Ar commit
-must be on the same branch as the work tree's base commit.
+should be on the same branch as the work tree's base commit.
 The expected argument is a reference or a commit ID SHA1 hash.
 An abbreviated hash argument will be expanded to a full SHA1 hash
 automatically, provided the abbreviation is unique.
diff --git a/got/got.c b/got/got.c
index 51bedee..320079e 100644
--- a/got/got.c
+++ b/got/got.c
@@ -7902,7 +7902,6 @@ cmd_cherrypick(int argc, char *argv[])
 	struct got_object_id *commit_id = NULL;
 	struct got_commit_object *commit = NULL;
 	struct got_object_qid *pid;
-	struct got_reference *head_ref = NULL;
 	int ch;
 	struct got_update_progress_arg upa;
 
@@ -7966,21 +7965,6 @@ cmd_cherrypick(int argc, char *argv[])
 	if (error)
 		goto done;
 
-	error = got_ref_open(&head_ref, repo,
-	    got_worktree_get_head_ref_name(worktree), 0);
-	if (error != NULL)
-		goto done;
-
-	error = check_same_branch(commit_id, head_ref, NULL, repo);
-	if (error) {
-		if (error->code != GOT_ERR_ANCESTRY)
-			goto done;
-		error = NULL;
-	} else {
-		error = got_error(GOT_ERR_SAME_BRANCH);
-		goto done;
-	}
-
 	error = got_object_open_as_commit(&commit, repo, commit_id);
 	if (error)
 		goto done;
@@ -7999,8 +7983,6 @@ done:
 	if (commit)
 		got_object_commit_close(commit);
 	free(commit_id_str);
-	if (head_ref)
-		got_ref_close(head_ref);
 	if (worktree)
 		got_worktree_close(worktree);
 	if (repo) {
@@ -8028,7 +8010,6 @@ cmd_backout(int argc, char *argv[])
 	struct got_object_id *commit_id = NULL;
 	struct got_commit_object *commit = NULL;
 	struct got_object_qid *pid;
-	struct got_reference *head_ref = NULL;
 	int ch;
 	struct got_update_progress_arg upa;
 
@@ -8091,15 +8072,6 @@ cmd_backout(int argc, char *argv[])
 	if (error)
 		goto done;
 
-	error = got_ref_open(&head_ref, repo,
-	    got_worktree_get_head_ref_name(worktree), 0);
-	if (error != NULL)
-		goto done;
-
-	error = check_same_branch(commit_id, head_ref, NULL, repo);
-	if (error)
-		goto done;
-
 	error = got_object_open_as_commit(&commit, repo, commit_id);
 	if (error)
 		goto done;
@@ -8122,8 +8094,6 @@ done:
 	if (commit)
 		got_object_commit_close(commit);
 	free(commit_id_str);
-	if (head_ref)
-		got_ref_close(head_ref);
 	if (worktree)
 		got_worktree_close(worktree);
 	if (repo) {