From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Martin Langhoff" <martin.langhoff@gmail.com>,
"Jeff King" <peff@peff.net>, "Steffen Prohaska" <prohaska@zib.de>,
"Daniel Barkalow" <barkalow@iabervon.org>,
"Johannes Schindelin" <johannes.schindelin@gmx.de>
Subject: [PATCH] checkout: tone down the "forked status" diagnostic messages
Date: Wed, 20 Feb 2008 15:05:23 -0800 [thread overview]
Message-ID: <7vy79f2pqk.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <46a038f90802190903g1a19e38i30198b368a800a89@mail.gmail.com> (Martin Langhoff's message of "Wed, 20 Feb 2008 06:03:01 +1300")
When checking out a branch that is behind or forked from a
branch you are building on top of, we used to show full
left-right log but if you already _know_ you have long history
since you forked, it is a bit too much.
This tones down the message quite a bit, by only showing the
number of commits each side has since they diverged.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* This obviously comes on top of the earlier patch of mine,
which in turn is on top of Daniel's "checkout written in C".
builtin-checkout.c | 102 ++++++++++++++++++++++++++++++++--------------------
1 files changed, 63 insertions(+), 39 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 5291f72..261f67f 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -301,64 +301,88 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
char *base;
unsigned char sha1[20];
struct commit *ours, *theirs;
- const char *msgfmt;
char symmetric[84];
- int show_log;
+ struct rev_info revs;
+ const char *rev_argv[10];
+ int rev_argc;
+ int num_ours, num_theirs;
+ const char *remote_msg;
struct branch *branch = branch_get(NULL);
+ /*
+ * Nothing to report unless we are marked to build on top of
+ * somebody else.
+ */
if (!branch || !branch->merge)
return;
- base = branch->merge[0]->dst;
-
- ours = new->commit;
-
- sprintf(symmetric, "%s", sha1_to_hex(ours->object.sha1));
-
/*
- * Ok, it is tracking base; is it ahead of us?
+ * If what we used to build on no longer exists, there is
+ * nothing to report.
*/
+ base = branch->merge[0]->dst;
if (!resolve_ref(base, sha1, 1, NULL))
return;
- theirs = lookup_commit(sha1);
-
- sprintf(symmetric + 40, "...%s", sha1_to_hex(sha1));
+ theirs = lookup_commit(sha1);
+ ours = new->commit;
if (!hashcmp(sha1, ours->object.sha1))
return; /* we are the same */
- show_log = 1;
- if (in_merge_bases(theirs, &ours, 1)) {
- msgfmt = "You are ahead of the tracked branch '%s'\n";
- show_log = 0;
+ /* Run "rev-list --left-right ours...theirs" internally... */
+ rev_argc = 0;
+ rev_argv[rev_argc++] = NULL;
+ rev_argv[rev_argc++] = "--left-right";
+ rev_argv[rev_argc++] = symmetric;
+ rev_argv[rev_argc++] = "--";
+ rev_argv[rev_argc] = NULL;
+
+ strcpy(symmetric, sha1_to_hex(ours->object.sha1));
+ strcpy(symmetric + 40, "...");
+ strcpy(symmetric + 43, sha1_to_hex(theirs->object.sha1));
+
+ init_revisions(&revs, NULL);
+ setup_revisions(rev_argc, rev_argv, &revs, NULL);
+ prepare_revision_walk(&revs);
+
+ /* ... and count the commits on each side. */
+ num_ours = 0;
+ num_theirs = 0;
+ while (1) {
+ struct commit *c = get_revision(&revs);
+ if (!c)
+ break;
+ if (c->object.flags & SYMMETRIC_LEFT)
+ num_ours++;
+ else
+ num_theirs++;
}
- else if (in_merge_bases(ours, &theirs, 1))
- msgfmt = "Your branch can be fast-forwarded to the tracked branch '%s'\n";
- else
- msgfmt = "Both your branch and the tracked branch '%s' have own changes, you would eventually need to merge\n";
- if (!prefixcmp(base, "refs/remotes/"))
+ if (!prefixcmp(base, "refs/remotes/")) {
+ remote_msg = " remote";
base += strlen("refs/remotes/");
- fprintf(stderr, msgfmt, base);
-
- if (show_log) {
- const char *args[32];
- int ac;
-
- ac = 0;
- args[ac++] = "log";
- args[ac++] = "--pretty=oneline";
- args[ac++] = "--abbrev-commit";
- args[ac++] = "--left-right";
- args[ac++] = "--boundary";
- args[ac++] = symmetric;
- args[ac++] = "--";
- args[ac] = NULL;
-
- run_command_v_opt(args, RUN_GIT_CMD);
+ } else {
+ remote_msg = "";
}
-}
+ if (!num_theirs)
+ printf("Your branch is ahead of the tracked%s branch '%s' "
+ "by %d commit%s.\n",
+ remote_msg, base,
+ num_ours, (num_ours == 1) ? "" : "s");
+ else if (!num_ours)
+ printf("Your branch is behind of the tracked%s branch '%s' "
+ "by %d commit%s,\n"
+ "and can be fast-forwarded.\n",
+ remote_msg, base,
+ num_theirs, (num_theirs == 1) ? "" : "s");
+ else
+ printf("Your branch and the tracked%s branch '%s' "
+ "have diverged,\nand respectively "
+ "have %d and %d different commit(s) each.\n",
+ remote_msg, base,
+ num_ours, num_theirs);
+}
static void update_refs_for_switch(struct checkout_opts *opts,
struct branch_info *old,
next prev parent reply other threads:[~2008-02-20 23:06 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-08 4:44 Minor annoyance with git push Martin Langhoff
2008-02-08 4:50 ` Martin Langhoff
2008-02-08 7:48 ` Junio C Hamano
2008-02-09 11:22 ` Steffen Prohaska
2008-02-10 3:44 ` Junio C Hamano
2008-02-10 12:21 ` Johannes Schindelin
2008-02-08 11:52 ` Johannes Schindelin
2008-02-08 22:23 ` Martin Langhoff
2008-02-08 22:27 ` Mike Hommey
2008-02-08 5:38 ` Sean
2008-02-08 6:29 ` Steffen Prohaska
2008-02-08 11:50 ` Johannes Schindelin
2008-02-08 22:27 ` Martin Langhoff
2008-02-08 22:57 ` Johannes Schindelin
2008-02-09 2:46 ` Jeff King
2008-02-09 2:54 ` Jeff King
2008-02-09 13:04 ` Johannes Schindelin
2008-02-09 13:22 ` Jeff King
2008-02-09 11:22 ` Steffen Prohaska
2008-02-09 3:00 ` Jeff King
2008-02-09 3:24 ` Junio C Hamano
2008-02-09 3:55 ` Jeff King
2008-02-09 11:50 ` Martin Langhoff
2008-02-09 13:06 ` Johannes Schindelin
2008-02-10 2:24 ` Junio C Hamano
2008-02-10 10:13 ` Jeff King
2008-02-10 12:22 ` Johannes Schindelin
2008-02-17 1:08 ` [RFC] checkout to notice forks (Re: Minor annoyance with git push) Junio C Hamano
2008-02-17 3:31 ` Daniel Barkalow
2008-02-17 4:11 ` Junio C Hamano
2008-02-17 6:39 ` Daniel Barkalow
2008-02-17 7:37 ` Junio C Hamano
2008-02-17 17:36 ` Daniel Barkalow
2008-02-17 12:28 ` Jeff King
2008-02-20 16:01 ` Santi Béjar
2008-02-19 17:03 ` Martin Langhoff
2008-02-20 23:05 ` Junio C Hamano [this message]
2008-02-21 1:45 ` [PATCH] checkout: tone down the "forked status" diagnostic messages Jeff King
2008-02-21 3:42 ` [PATCH] checkout: updates to tracking report Junio C Hamano
2008-02-21 5:27 ` Jay Soffian
2008-02-21 17:02 ` Daniel Barkalow
2008-02-21 2:56 ` [PATCH] checkout: tone down the "forked status" diagnostic messages Jay Soffian
2008-02-09 10:53 ` Minor annoyance with git push Steffen Prohaska
2008-02-09 13:10 ` Johannes Schindelin
2008-02-10 2:07 ` Junio C Hamano
2008-02-10 2:15 ` Johannes Schindelin
2008-02-10 10:17 ` Jeff King
2008-02-10 12:20 ` Johannes Schindelin
2008-02-10 12:23 ` Jeff King
2008-02-10 13:04 ` Johannes Schindelin
2008-02-10 13:07 ` Jeff King
2008-02-20 8:23 ` Junio C Hamano
2008-02-20 13:06 ` Johannes Schindelin
2008-02-20 15:20 ` Jay Soffian
2008-02-20 15:38 ` Johannes Schindelin
2008-02-21 22:35 ` Steven Walter
2008-02-22 0:11 ` Johannes Schindelin
2008-02-20 14:03 ` Jeff King
2008-02-20 17:54 ` Junio C Hamano
2008-02-20 18:15 ` Jeff King
2008-02-20 18:17 ` Jeff King
2008-02-20 18:19 ` Junio C Hamano
2008-02-20 18:23 ` Jeff King
2008-02-10 14:03 ` Wincent Colaiuta
2008-02-10 15:02 ` Steven Walter
2008-02-10 16:29 ` Johannes Schindelin
2008-02-10 16:26 ` Johannes Schindelin
2008-02-10 18:18 ` Wincent Colaiuta
2008-02-10 22:34 ` Jeff King
2008-02-10 22:59 ` Junio C Hamano
2008-02-10 23:29 ` Jeff King
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=7vy79f2pqk.fsf_-_@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=martin.langhoff@gmail.com \
--cc=peff@peff.net \
--cc=prohaska@zib.de \
/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).