Commit Diff


commit - 0f52093fbc9683aec0c9d1f9a45c1eaed6b8708f
commit + 705cce7454a397f5c9eaa7a44ef383e0659d1242
blob - 1f51749ddf6911fb3d86837fa46e6565d991b44c
blob + 90e7cbbe69e2d39195690286398754f1c7be54bb
--- cvg/cvg.c
+++ cvg/cvg.c
@@ -102,7 +102,6 @@ __dead static void	usage_diff(void);
 __dead static void	usage_blame(void);
 __dead static void	usage_tree(void);
 __dead static void	usage_status(void);
-__dead static void	usage_ref(void);
 __dead static void	usage_tag(void);
 __dead static void	usage_add(void);
 __dead static void	usage_remove(void);
@@ -123,7 +122,6 @@ static const struct got_error*		cmd_diff(int, char *[]
 static const struct got_error*		cmd_blame(int, char *[]);
 static const struct got_error*		cmd_tree(int, char *[]);
 static const struct got_error*		cmd_status(int, char *[]);
-static const struct got_error*		cmd_ref(int, char *[]);
 static const struct got_error*		cmd_tag(int, char *[]);
 static const struct got_error*		cmd_add(int, char *[]);
 static const struct got_error*		cmd_remove(int, char *[]);
@@ -145,7 +143,6 @@ static const struct got_cmd got_commands[] = {
 	{ "blame",	cmd_blame,	usage_blame,	"bl" },
 	{ "tree",	cmd_tree,	usage_tree,	"tr" },
 	{ "status",	cmd_status,	usage_status,	"st" },
-	{ "ref",	cmd_ref,	usage_ref,	"" },
 	{ "tag",	cmd_tag,	usage_tag,	"" },
 	{ "add",	cmd_add,	usage_add,	"" },
 	{ "remove",	cmd_remove,	usage_remove,	"rm" },
@@ -1997,37 +1994,6 @@ update_wanted_ref(const char *refname, struct got_obje
 	}
 done:
 	free(remote_refname);
-	return err;
-}
-
-static const struct got_error *
-delete_ref(struct got_repository *repo, struct got_reference *ref)
-{
-	const struct got_error *err = NULL;
-	struct got_object_id *id = NULL;
-	char *id_str = NULL;
-	const char *target;
-
-	if (got_ref_is_symbolic(ref)) {
-		target = got_ref_get_symref_target(ref);
-	} else {
-		err = got_ref_resolve(&id, repo, ref);
-		if (err)
-			goto done;
-		err = got_object_id_str(&id_str, id);
-		if (err)
-			goto done;
-		target = id_str;
-	}
-
-	err = got_ref_delete(ref, repo);
-	if (err)
-		goto done;
-
-	printf("Deleted %s: %s\n", got_ref_get_name(ref), target);
-done:
-	free(id);
-	free(id_str);
 	return err;
 }
 
@@ -5810,299 +5776,7 @@ done:
 	}
 
 	got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH);
-	free(cwd);
-	return error;
-}
-
-__dead static void
-usage_ref(void)
-{
-	fprintf(stderr, "usage: %s ref [-dlt] [-c object] [-r repository-path] "
-	    "[-s reference] [name]\n", getprogname());
-	exit(1);
-}
-
-static const struct got_error *
-list_refs(struct got_repository *repo, const char *refname, int sort_by_time)
-{
-	static const struct got_error *err = NULL;
-	struct got_reflist_head refs;
-	struct got_reflist_entry *re;
-
-	TAILQ_INIT(&refs);
-	err = got_ref_list(&refs, repo, refname, sort_by_time ?
-	    got_ref_cmp_by_commit_timestamp_descending : got_ref_cmp_by_name,
-	    repo);
-	if (err)
-		return err;
-
-	TAILQ_FOREACH(re, &refs, entry) {
-		char *refstr;
-		refstr = got_ref_to_str(re->ref);
-		if (refstr == NULL) {
-			err = got_error_from_errno("got_ref_to_str");
-			break;
-		}
-		printf("%s: %s\n", got_ref_get_name(re->ref), refstr);
-		free(refstr);
-	}
-
-	got_ref_list_free(&refs);
-	return err;
-}
-
-static const struct got_error *
-delete_ref_by_name(struct got_repository *repo, const char *refname)
-{
-	const struct got_error *err;
-	struct got_reference *ref;
-
-	err = got_ref_open(&ref, repo, refname, 0);
-	if (err)
-		return err;
-
-	err = delete_ref(repo, ref);
-	got_ref_close(ref);
-	return err;
-}
-
-static const struct got_error *
-add_ref(struct got_repository *repo, const char *refname, const char *target)
-{
-	const struct got_error *err = NULL;
-	struct got_object_id *id = NULL;
-	struct got_reference *ref = NULL;
-	struct got_reflist_head refs;
-
-	/*
-	 * Don't let the user create a reference name with a leading '-'.
-	 * While technically a valid reference name, this case is usually
-	 * an unintended typo.
-	 */
-	if (refname[0] == '-')
-		return got_error_path(refname, GOT_ERR_REF_NAME_MINUS);
-
-	TAILQ_INIT(&refs);
-	err = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
-	if (err)
-		goto done;
-	err = got_repo_match_object_id(&id, NULL, target, GOT_OBJ_TYPE_ANY,
-	    &refs, repo);
-	got_ref_list_free(&refs);
-	if (err)
-		goto done;
-
-	err = got_ref_alloc(&ref, refname, id);
-	if (err)
-		goto done;
-
-	err = got_ref_write(ref, repo);
-done:
-	if (ref)
-		got_ref_close(ref);
-	free(id);
-	return err;
-}
-
-static const struct got_error *
-add_symref(struct got_repository *repo, const char *refname, const char *target)
-{
-	const struct got_error *err = NULL;
-	struct got_reference *ref = NULL;
-	struct got_reference *target_ref = NULL;
-
-	/*
-	 * Don't let the user create a reference name with a leading '-'.
-	 * While technically a valid reference name, this case is usually
-	 * an unintended typo.
-	 */
-	if (refname[0] == '-')
-		return got_error_path(refname, GOT_ERR_REF_NAME_MINUS);
-
-	err = got_ref_open(&target_ref, repo, target, 0);
-	if (err)
-		return err;
-
-	err = got_ref_alloc_symref(&ref, refname, target_ref);
-	if (err)
-		goto done;
-
-	err = got_ref_write(ref, repo);
-done:
-	if (target_ref)
-		got_ref_close(target_ref);
-	if (ref)
-		got_ref_close(ref);
-	return err;
-}
-
-static const struct got_error *
-cmd_ref(int argc, char *argv[])
-{
-	const struct got_error *error = NULL;
-	struct got_repository *repo = NULL;
-	struct got_worktree *worktree = NULL;
-	char *cwd = NULL, *repo_path = NULL;
-	int ch, do_list = 0, do_delete = 0, sort_by_time = 0;
-	const char *obj_arg = NULL, *symref_target= NULL;
-	char *refname = NULL;
-	int *pack_fds = NULL;
-
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath fattr flock proc exec "
-	    "sendfd unveil", NULL) == -1)
-		err(1, "pledge");
-#endif
-
-	while ((ch = getopt(argc, argv, "c:dlr:s:t")) != -1) {
-		switch (ch) {
-		case 'c':
-			obj_arg = optarg;
-			break;
-		case 'd':
-			do_delete = 1;
-			break;
-		case 'l':
-			do_list = 1;
-			break;
-		case 'r':
-			repo_path = realpath(optarg, NULL);
-			if (repo_path == NULL)
-				return got_error_from_errno2("realpath",
-				    optarg);
-			got_path_strip_trailing_slashes(repo_path);
-			break;
-		case 's':
-			symref_target = optarg;
-			break;
-		case 't':
-			sort_by_time = 1;
-			break;
-		default:
-			usage_ref();
-			/* NOTREACHED */
-		}
-	}
-
-	if (obj_arg && do_list)
-		option_conflict('c', 'l');
-	if (obj_arg && do_delete)
-		option_conflict('c', 'd');
-	if (obj_arg && symref_target)
-		option_conflict('c', 's');
-	if (symref_target && do_delete)
-		option_conflict('s', 'd');
-	if (symref_target && do_list)
-		option_conflict('s', 'l');
-	if (do_delete && do_list)
-		option_conflict('d', 'l');
-	if (sort_by_time && !do_list)
-		errx(1, "-t option requires -l option");
-
-	argc -= optind;
-	argv += optind;
-
-	if (do_list) {
-		if (argc != 0 && argc != 1)
-			usage_ref();
-		if (argc == 1) {
-			refname = strdup(argv[0]);
-			if (refname == NULL) {
-				error = got_error_from_errno("strdup");
-				goto done;
-			}
-		}
-	} else {
-		if (argc != 1)
-			usage_ref();
-		refname = strdup(argv[0]);
-		if (refname == NULL) {
-			error = got_error_from_errno("strdup");
-			goto done;
-		}
-	}
-
-	if (refname)
-		got_path_strip_trailing_slashes(refname);
-
-	cwd = getcwd(NULL, 0);
-	if (cwd == NULL) {
-		error = got_error_from_errno("getcwd");
-		goto done;
-	}
-
-	error = got_repo_pack_fds_open(&pack_fds);
-	if (error != NULL)
-		goto done;
-
-	if (repo_path == NULL) {
-		error = got_worktree_open(&worktree, cwd);
-		if (error && error->code != GOT_ERR_NOT_WORKTREE)
-			goto done;
-		else
-			error = NULL;
-		if (worktree) {
-			repo_path =
-			    strdup(got_worktree_get_repo_path(worktree));
-			if (repo_path == NULL)
-				error = got_error_from_errno("strdup");
-			if (error)
-				goto done;
-		} else {
-			repo_path = strdup(cwd);
-			if (repo_path == NULL) {
-				error = got_error_from_errno("strdup");
-				goto done;
-			}
-		}
-	}
-
-	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
-	if (error != NULL)
-		goto done;
-
-#ifndef PROFILE
-	if (do_list) {
-		/* Remove "cpath" promise. */
-		if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
-		    NULL) == -1)
-			err(1, "pledge");
-	}
-#endif
-
-	error = apply_unveil(got_repo_get_path(repo), do_list,
-	    worktree ? got_worktree_get_root_path(worktree) : NULL);
-	if (error)
-		goto done;
-
-	if (do_list)
-		error = list_refs(repo, refname, sort_by_time);
-	else if (do_delete)
-		error = delete_ref_by_name(repo, refname);
-	else if (symref_target)
-		error = add_symref(repo, refname, symref_target);
-	else {
-		if (obj_arg == NULL)
-			usage_ref();
-		error = add_ref(repo, refname, obj_arg);
-	}
-done:
-	free(refname);
-	if (repo) {
-		const struct got_error *close_err = got_repo_close(repo);
-		if (error == NULL)
-			error = close_err;
-	}
-	if (worktree)
-		got_worktree_close(worktree);
-	if (pack_fds) {
-		const struct got_error *pack_err =
-		    got_repo_pack_fds_close(pack_fds);
-		if (error == NULL)
-			error = pack_err;
-	}
 	free(cwd);
-	free(repo_path);
 	return error;
 }