From: marcandre.lureau@redhat.com
To: git@vger.kernel.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH] RFC: allow branch --edit-description during rebase
Date: Fri, 10 Jan 2020 11:19:29 +0400 [thread overview]
Message-ID: <20200110071929.119000-1-marcandre.lureau@redhat.com> (raw)
From: Marc-André Lureau <marcandre.lureau@redhat.com>
This patch aims to allow editing of branch description during a rebase.
A common use case of rebasing is to iterate over a series of patches
after receiving reviews. During the rebase, various patches will be
modified, and it is often requested to put a summary of the changes for
the next version in the cover letter ("v2: - fixed this, - changed
that.."). This helps the reviewer to focus on the difference with the
previous version. Unfortunately, git branch --edit-description doesn't
allow yet to modify the content during a rebase, and forces the author
to use memory muscles to update the description after finishing the
rebase.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
builtin/branch.c | 19 ++++++++++++++++---
worktree.c | 19 +++++++++++++++++++
worktree.h | 7 +++++++
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index d8297f80ff..f7122d31d6 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -613,6 +613,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int icase = 0;
static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
struct ref_format format = REF_FORMAT_INIT;
+ struct wt_status_state state;
struct option options[] = {
OPT_GROUP(N_("Generic options")),
@@ -664,6 +665,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
setup_ref_filter_porcelain_msg();
+ memset(&state, 0, sizeof(state));
+
memset(&filter, 0, sizeof(filter));
filter.kind = FILTER_REFS_BRANCHES;
filter.abbrev = -1;
@@ -745,13 +748,21 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
string_list_clear(&output, 0);
return 0;
} else if (edit_description) {
- const char *branch_name;
+ const char *branch_name = NULL;
struct strbuf branch_ref = STRBUF_INIT;
if (!argc) {
- if (filter.detached)
+ if (filter.detached) {
+ const struct worktree *wt = worktree_get_current();
+
+ if (wt_status_check_rebase(wt, &state)) {
+ branch_name = state.branch;
+ }
+
+ if (!branch_name)
die(_("Cannot give description to detached HEAD"));
- branch_name = head;
+ } else
+ branch_name = head;
} else if (argc == 1)
branch_name = argv[0];
else
@@ -851,5 +862,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
} else
usage_with_options(builtin_branch_usage, options);
+ free(state.branch);
+ free(state.onto);
return 0;
}
diff --git a/worktree.c b/worktree.c
index 5b4793caa3..0318c6f6a6 100644
--- a/worktree.c
+++ b/worktree.c
@@ -396,6 +396,25 @@ int is_worktree_being_bisected(const struct worktree *wt,
return found_rebase;
}
+const struct worktree *worktree_get_current(void)
+{
+ static struct worktree **worktrees;
+ int i = 0;
+
+ if (worktrees)
+ free_worktrees(worktrees);
+ worktrees = get_worktrees(0);
+
+ for (i = 0; worktrees[i]; i++) {
+ struct worktree *wt = worktrees[i];
+
+ if (wt->is_current)
+ return wt;
+ }
+
+ return NULL;
+}
+
/*
* note: this function should be able to detect shared symref even if
* HEAD is temporarily detached (e.g. in the middle of rebase or
diff --git a/worktree.h b/worktree.h
index caecc7a281..4fe2b78d24 100644
--- a/worktree.h
+++ b/worktree.h
@@ -91,6 +91,13 @@ void free_worktrees(struct worktree **);
const struct worktree *find_shared_symref(const char *symref,
const char *target);
+
+/*
+ * Return the current worktree. The result may be destroyed by the
+ * next call.
+ */
+const struct worktree *worktree_get_current(void);
+
/*
* Similar to head_ref() for all HEADs _except_ one from the current
* worktree, which is covered by head_ref().
base-commit: 042ed3e048af08014487d19196984347e3be7d1c
prerequisite-patch-id: 9b3cf75545ec4a1e702c8c2b2aae8edf241b87f2
--
2.25.0.rc1.20.g2443f3f80d.dirty
next reply other threads:[~2020-01-10 7:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 7:19 marcandre.lureau [this message]
2020-01-10 13:18 ` [PATCH] RFC: allow branch --edit-description during rebase SZEDER Gábor
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=20200110071929.119000-1-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.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).