From: Alex Torok <alext9@gmail.com>
To: git@vger.kernel.org
Cc: Alex Torok <alext9@gmail.com>
Subject: [PATCH v2 1/2] rebase: refactor dwim_ref_or_die from merge-base.c
Date: Thu, 5 Dec 2019 18:57:03 -0500 [thread overview]
Message-ID: <20191205235704.31385-2-alext9@gmail.com> (raw)
In-Reply-To: <20191205235704.31385-1-alext9@gmail.com>
Pull logic for getting the full dwim ref name from a passed in ref name
out of the handle_fork_point function of merge-base.c. This will allow
git-rebase --fork-point to use the same method for getting the full ref
name before calling get_fork_point.
I saw other *_or_die methods in other places and using that pattern
seemed sane here.
I'm not 100% sure about the name or signature of dwim_ref_or_die. I feel
like it should be named something like dwim_ref_name_or_die,
unique_dwim_ref_or_die, or should be including the object_id argument
even though it isn't used by the calling merge_base code, and won't be
used in rebase.
This is my first patch submission for git, and I'd appreciate some
feedback on naming/style wrt to this.
Signed-off-by: Alex Torok <alext9@gmail.com>
---
builtin/merge-base.c | 9 +--------
refs.c | 14 ++++++++++++++
refs.h | 1 +
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index e3f8da13b6..edd16f9fcd 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -118,14 +118,7 @@ static int handle_fork_point(int argc, const char **argv)
struct commit *derived, *fork_point;
const char *commitname;
- switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
- case 0:
- die("No such ref: '%s'", argv[0]);
- case 1:
- break; /* good */
- default:
- die("Ambiguous refname: '%s'", argv[0]);
- }
+ dwim_ref_or_die(argv[0], strlen(argv[0]), &refname);
commitname = (argc == 2) ? argv[1] : "HEAD";
if (get_oid(commitname, &oid))
diff --git a/refs.c b/refs.c
index 1ab0bb54d3..3b778f2df9 100644
--- a/refs.c
+++ b/refs.c
@@ -639,6 +639,20 @@ int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
return repo_dwim_ref(the_repository, str, len, oid, ref);
}
+void dwim_ref_or_die(const char *str, int len, char **ref)
+{
+ struct object_id discard;
+ switch (dwim_ref(str, len, &discard, ref)) {
+ case 0:
+ die("No such ref: '%s'", str);
+ case 1:
+ break; /* good */
+ default:
+ die("Ambiguous refname: '%s'", str);
+ }
+}
+
+
int expand_ref(struct repository *repo, const char *str, int len,
struct object_id *oid, char **ref)
{
diff --git a/refs.h b/refs.h
index 730d05ad91..a961662382 100644
--- a/refs.h
+++ b/refs.h
@@ -154,6 +154,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_
int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
+void dwim_ref_or_die(const char *str, int len, char **ref);
/*
* A ref_transaction represents a collection of reference updates that
* should succeed or fail together.
--
2.17.1
next prev parent reply other threads:[~2019-12-05 23:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 22:53 [PATCH 0/3] rebase: fix bug in --fork-point Alex Torok
2019-12-05 22:53 ` [PATCH 1/3] rebase: add test for rebase --fork-point with short upstream Alex Torok
2019-12-05 23:04 ` Junio C Hamano
2019-12-05 23:25 ` Alex Torok
2019-12-05 22:53 ` [PATCH 2/3] rebase: refactor dwim_ref_or_die from merge-base.c Alex Torok
2019-12-05 22:53 ` [PATCH 3/3] rebase: fix rebase to use full ref to find fork-point Alex Torok
2019-12-05 23:57 ` [PATCH v2 0/2] rebase: fix bug in --fork-point Alex Torok
2019-12-05 23:57 ` Alex Torok [this message]
2019-12-06 1:23 ` [PATCH v2 1/2] rebase: refactor dwim_ref_or_die from merge-base.c Denton Liu
2019-12-06 13:13 ` Alex Torok
2019-12-05 23:57 ` [PATCH v2 2/2] rebase: find --fork-point with full ref Alex Torok
2019-12-06 1:48 ` Denton Liu
2019-12-06 10:52 ` Phillip Wood
2019-12-06 13:46 ` Alex Torok
2019-12-06 19:11 ` [PATCH v2 2/2] rebase: find --fork-point with full refgg Denton Liu
2019-12-06 19:35 ` Phillip Wood
2019-12-09 14:53 ` [PATCH v3 0/1] rebase: fix --fork-point with short ref upstream Alex Torok
2019-12-09 14:53 ` [PATCH v3 1/1] rebase: fix --fork-point with short refname Alex Torok
2019-12-09 18:51 ` Junio C Hamano
2019-12-11 1:21 ` Alex Torok
2019-12-11 12:21 ` Denton Liu
2019-12-11 16:02 ` Eric Sunshine
2020-02-11 18:15 ` [PATCH v4 1/1] rebase: --fork-point regression fix 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=20191205235704.31385-2-alext9@gmail.com \
--to=alext9@gmail.com \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).