From: Xiaolong Ye <xiaolong.ye@intel.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Cc: fengguang.wu@intel.com, ying.huang@intel.com,
philip.li@intel.com, julie.du@intel.com,
Xiaolong Ye <xiaolong.ye@intel.com>
Subject: [PATCH v2 3/4] format-patch: introduce --base=auto option
Date: Wed, 23 Mar 2016 16:52:26 +0800 [thread overview]
Message-ID: <1458723147-7335-4-git-send-email-xiaolong.ye@intel.com> (raw)
In-Reply-To: <1458723147-7335-1-git-send-email-xiaolong.ye@intel.com>
Introduce --base=auto to record the base commit info automatically, the base_commit
will be the tip commit of the upstream branch. If upstream branch cannot be determined,
it will just record the parent's commit id and patch id.
Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
---
builtin/log.c | 70 +++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 51 insertions(+), 19 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index d3804b3..e8a3964 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1187,6 +1187,8 @@ static int from_callback(const struct option *opt, const char *arg, int unset)
struct base_tree_info {
struct object_id base_commit;
+ struct object_id parent_commit;
+ struct object_id parent_patch_id;
int nr_patch_id, alloc_patch_id;
struct object_id *patch_id;
};
@@ -1199,15 +1201,38 @@ static void prepare_bases(struct base_tree_info *bases,
struct rev_info revs;
struct diff_options diffopt;
struct object_id *patch_id;
+ struct branch *curr_branch;
+ const char *upstream;
unsigned char sha1[20];
int pos = 0;
if (!prerequisite_head)
return;
- base = lookup_commit_reference_by_name(base_commit);
- if (!base)
- die(_("Unknown commit %s"), base_commit);
- oidcpy(&bases->base_commit, &base->object.oid);
+
+ diff_setup(&diffopt);
+ DIFF_OPT_SET(&diffopt, RECURSIVE);
+ diff_setup_done(&diffopt);
+
+ if (!strcmp(base_commit, "auto")) {
+ curr_branch = branch_get(NULL);
+ upstream = branch_get_upstream(curr_branch, NULL);
+ if (upstream) {
+ if (get_sha1(upstream, sha1))
+ die(_("Failed to resolve '%s' as a valid ref."), upstream);
+ base = lookup_commit_or_die(sha1, "upstream base");
+ oidcpy(&bases->base_commit, &base->object.oid);
+ } else {
+ commit_patch_id(prerequisite_head, &diffopt, sha1);
+ oidcpy(&bases->parent_commit, &prerequisite_head->object.oid);
+ hashcpy(bases->parent_patch_id.hash, sha1);
+ return;
+ }
+ } else {
+ base = lookup_commit_reference_by_name(base_commit);
+ if (!base)
+ die(_("Unknown commit %s"), base_commit);
+ oidcpy(&bases->base_commit, &base->object.oid);
+ }
if (base == prerequisite_head)
return;
@@ -1223,10 +1248,6 @@ static void prepare_bases(struct base_tree_info *bases,
prerequisite_head->object.flags |= 0;
add_pending_object(&revs, &prerequisite_head->object, "prerequisite-head");
- diff_setup(&diffopt);
- DIFF_OPT_SET(&diffopt, RECURSIVE);
- diff_setup_done(&diffopt);
-
if (prepare_revision_walk(&revs))
die(_("revision walk setup failed"));
/*
@@ -1249,22 +1270,33 @@ static void print_bases(struct base_tree_info *bases)
int i;
/* Only do this once, either for the cover or for the first one */
- if (is_null_oid(&bases->base_commit))
+ if (is_null_oid(&bases->base_commit) && is_null_oid(&bases->parent_commit))
return;
- printf("** base-commit-info **\n");
+ if (!is_null_oid(&bases->base_commit)) {
+ printf("** base-commit-info **\n");
+
+ /* Show the base commit */
+ printf("base-commit: %s\n", oid_to_hex(&bases->base_commit));
- /* Show the base commit */
- printf("base-commit: %s\n", oid_to_hex(&bases->base_commit));
+ /* Show the prerequisite patches */
+ for (i = 0; i < bases->nr_patch_id; i++)
+ printf("prerequisite-patch-id: %s\n", oid_to_hex(&bases->patch_id[i]));
- /* Show the prerequisite patches */
- for (i = 0; i < bases->nr_patch_id; i++)
- printf("prerequisite-patch-id: %s\n", oid_to_hex(&bases->patch_id[i]));
+ free(bases->patch_id);
+ bases->nr_patch_id = 0;
+ bases->alloc_patch_id = 0;
+ oidclr(&bases->base_commit);
+ } else if (!is_null_oid(&bases->parent_commit)) {
+ printf("** parent-commit-info **\n");
- free(bases->patch_id);
- bases->nr_patch_id = 0;
- bases->alloc_patch_id = 0;
- oidclr(&bases->base_commit);
+ /* Show the parent commit */
+ printf("parent-commit: %s\n", oid_to_hex(&bases->parent_commit));
+ /* Show the parent patch id */
+ printf("parent-patch-id: %s\n", oid_to_hex(&bases->parent_patch_id));
+
+ oidclr(&bases->parent_commit);
+ }
}
int cmd_format_patch(int argc, const char **argv, const char *prefix)
--
2.8.0.rc4.4.ga41a987
next prev parent reply other threads:[~2016-03-23 8:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-23 8:52 [PATCH v2 0/4] Add an option to git-format-patch to record base tree info Xiaolong Ye
2016-03-23 8:52 ` [PATCH v2 1/4] patch-ids: make commit_patch_id() a public helper function Xiaolong Ye
2016-03-23 8:52 ` [PATCH v2 2/4] format-patch: add '--base' option to record base tree info Xiaolong Ye
2016-03-23 18:08 ` Junio C Hamano
2016-03-24 3:08 ` Ye Xiaolong
2016-03-23 8:52 ` Xiaolong Ye [this message]
2016-03-23 18:25 ` [PATCH v2 3/4] format-patch: introduce --base=auto option Junio C Hamano
2016-03-24 4:19 ` Ye Xiaolong
2016-03-24 17:01 ` Junio C Hamano
2016-04-01 5:07 ` Ye Xiaolong
2016-04-01 16:36 ` Junio C Hamano
2016-03-23 8:52 ` [PATCH v2 4/4] format-patch: introduce format.base configuration Xiaolong Ye
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=1458723147-7335-4-git-send-email-xiaolong.ye@intel.com \
--to=xiaolong.ye@intel.com \
--cc=fengguang.wu@intel.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=julie.du@intel.com \
--cc=philip.li@intel.com \
--cc=ying.huang@intel.com \
/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).