Re: [PATCH v2] builtin/branch.c: remove useless branch_get
> > branch_get sometimes returns current_branch, which can be NULL (e.g., if > > you're on a detached HEAD). Try: > > > > $ git branch HEAD > > fatal: no such branch 'HEAD' > > > > $ git branch '' > > fatal: no such branch '' > > > > However, it seems weird that we'd check those cases here (and provide > > such lousy messages). And indeed, dropping that and letting us > > eventually hit create_branch() gives a much better message: > > > > $ git branch HEAD > > fatal: 'HEAD' is not a valid branch name. > > > > $ git branch '' > > fatal: '' is not a valid branch name. > > This explanation is perfect, of course. ;) > > I still wondered if you had another motivation hinted at in your > original mail, though (some weirdness with running branch_get early). > It's OK if there isn't one, but I just want to make sure we capture all > of the details. > Yes, this explanation is perfect. ;) > Other than that question, the patch looks good to me. > > -Peff
[PATCH v2] builtin/branch.c: remove useless branch_get
branch_get sometimes returns current_branch, which can be NULL (e.g., if you're on a detached HEAD). Try: $ git branch HEAD fatal: no such branch 'HEAD' $ git branch '' fatal: no such branch '' However, it seems weird that we'd check those cases here (and provide such lousy messages). And indeed, dropping that and letting us eventually hit create_branch() gives a much better message: $ git branch HEAD fatal: 'HEAD' is not a valid branch name. $ git branch '' fatal: '' is not a valid branch name. Signed-off-by: Tao Qingyun --- builtin/branch.c | 5 - 1 file changed, 5 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index c396c41533..2367703034 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -809,11 +809,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix) git_config_set_multivar(buf.buf, NULL, NULL, 1); strbuf_release(); } else if (argc > 0 && argc <= 2) { - struct branch *branch = branch_get(argv[0]); - - if (!branch) - die(_("no such branch '%s'"), argv[0]); - if (filter.kind != FILTER_REFS_BRANCHES) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); -- 2.19.0
[PATCH v2] branch: trivial style fix
Signed-off-by: Tao Qingyun --- builtin/branch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index c396c41533..0aa3dac27b 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -716,8 +716,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) print_columns(, colopts, NULL); string_list_clear(, 0); return 0; - } - else if (edit_description) { + } else if (edit_description) { const char *branch_name; struct strbuf branch_ref = STRBUF_INIT; -- 2.19.0
Re: [PATCH] branch: trivial style fix
>Sorry for the slow reply. For some reason I do not think your message >here made it to the list (but I don't see anything obviously wrong with >it). Yes, I cann't send message to the list using my email clinet, I don't know why. The only way I can make it is using `git send-email`(including this message).
[PATCH] builtin/branch.c: remove useless branch_get
Signed-off-by: Tao Qingyun --- builtin/branch.c | 5 - 1 file changed, 5 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index c396c41533..2367703034 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -809,11 +809,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix) git_config_set_multivar(buf.buf, NULL, NULL, 1); strbuf_release(); } else if (argc > 0 && argc <= 2) { - struct branch *branch = branch_get(argv[0]); - - if (!branch) - die(_("no such branch '%s'"), argv[0]); - if (filter.kind != FILTER_REFS_BRANCHES) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); -- 2.19.0
[Question] builtin/branch.c
Hi, I am learning `builtin/branch.c`. I find that it will call `branch_get` before create and [un]set upstream, and die with "no such branch" if failed. but `branch_get` seems never fail, it is a get_or_create. Also, it was confused that getting a branch before it has created. builtin/branch.c #811 } else if (argc > 0 && argc <= 2) { struct branch *branch = branch_get(argv[0]); if (!branch) die(_("no such branch '%s'"), argv[0]); if (filter.kind != FILTER_REFS_BRANCHES) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); if (track == BRANCH_TRACK_OVERRIDE) die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.")); create_branch(argv[0], (argc == 2) ? argv[1] : head, force, 0, reflog, quiet, track);
[PATCH] branch: trivial style fix
--- builtin/branch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index c396c41533..52aad0f602 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -222,10 +222,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } - for (i = 0; i < argc; i++, strbuf_reset()) { + for (i = 0; i < argc; i++) { char *target = NULL; int flags = 0; + strbuf_reset(); strbuf_branchname(, argv[i], allowed_interpret); free(name); name = mkpathdup(fmt, bname.buf); @@ -716,8 +717,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) print_columns(, colopts, NULL); string_list_clear(, 0); return 0; - } - else if (edit_description) { + } else if (edit_description) { const char *branch_name; struct strbuf branch_ref = STRBUF_INIT; -- 2.19.0
[PATCH v2] refs: docstring typo
Signed-off-by: Tao Qingyun --- refs/refs-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 04425d6d1e..1fe5a7a22f 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -282,7 +282,7 @@ int refs_rename_ref_available(struct ref_store *refs, * * // Access information about the current reference: * if (!(iter->flags & REF_ISSYMREF)) - * printf("%s is %s\n", iter->refname, oid_to_hex(>oid)); + * printf("%s is %s\n", iter->refname, oid_to_hex(iter->oid)); * * // If you need to peel the reference: * ref_iterator_peel(iter, ); -- 2.19.0
[PATCH] refs: docstirng typo
--- refs/refs-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 04425d6d1e..1fe5a7a22f 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -282,7 +282,7 @@ int refs_rename_ref_available(struct ref_store *refs, * * // Access information about the current reference: * if (!(iter->flags & REF_ISSYMREF)) - * printf("%s is %s\n", iter->refname, oid_to_hex(>oid)); + * printf("%s is %s\n", iter->refname, oid_to_hex(iter->oid)); * * // If you need to peel the reference: * ref_iterator_peel(iter, ); -- 2.18.0