Created
March 9, 2024 00:43
-
-
Save tsibley/81d144149812b009e833b9b1a667c2b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0ac09c0541385289ce6398699ca8e0e2596c8afa Mon Sep 17 00:00:00 2001 | |
From: Thomas Sibley <tom@zulutango.org> | |
Date: Fri, 8 Mar 2024 16:42:45 -0800 | |
Subject: [PATCH] wip! status: show last reflog timestamp of tracking branch | |
<https://metasocial.com/@trs/112062359954735355> | |
--- | |
remote.c | 58 +++++++++++++++++++++++++++++++++++++++++++------------- | |
1 file changed, 45 insertions(+), 13 deletions(-) | |
diff --git a/remote.c b/remote.c | |
index 9090632e96..5421fc3d33 100644 | |
--- a/remote.c | |
+++ b/remote.c | |
@@ -2259,6 +2259,28 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, | |
return stat_branch_pair(branch->refname, base, num_ours, num_theirs, abf); | |
} | |
+// XXX FIXME | |
+struct reflog_ent { | |
+ timestamp_t timestamp; | |
+ int tz; | |
+}; | |
+ | |
+// XXX FIXME | |
+static int reflog_ent_timestamp(struct object_id *ooid UNUSED, | |
+ struct object_id *noid UNUSED, | |
+ const char *email UNUSED, | |
+ timestamp_t timestamp, | |
+ int tz, | |
+ const char *message UNUSED, | |
+ void *cb_data) | |
+{ | |
+ struct reflog_ent *ent = cb_data; | |
+ ent->timestamp = timestamp; | |
+ ent->tz = tz; | |
+ return 1; | |
+} | |
+ | |
+ | |
/* | |
* Return true when there is anything to report, otherwise false. | |
*/ | |
@@ -2278,6 +2300,16 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, | |
upstream_is_gone = 1; | |
} | |
+ // XXX FIXME | |
+ struct reflog_ent base_reflog_ent = { 0, 0 }; | |
+ const char *as_of; | |
+ | |
+ if (for_each_reflog_ent_reverse(full_base, reflog_ent_timestamp, &base_reflog_ent)) { | |
+ as_of = show_date(base_reflog_ent.timestamp, base_reflog_ent.tz, DATE_MODE(RELATIVE)); | |
+ } else { | |
+ as_of = "unknown"; | |
+ } | |
+ | |
base = shorten_unambiguous_ref(full_base, 0); | |
if (upstream_is_gone) { | |
strbuf_addf(sb, | |
@@ -2288,45 +2320,45 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, | |
_(" (use \"git branch --unset-upstream\" to fixup)\n")); | |
} else if (!sti) { | |
strbuf_addf(sb, | |
- _("Your branch is up to date with '%s'.\n"), | |
- base); | |
+ _("Your branch is up to date with '%s' (as of %s).\n"), | |
+ base, as_of); | |
} else if (abf == AHEAD_BEHIND_QUICK) { | |
strbuf_addf(sb, | |
- _("Your branch and '%s' refer to different commits.\n"), | |
- base); | |
+ _("Your branch and '%s' (as of %s) refer to different commits.\n"), | |
+ base, as_of); | |
if (advice_enabled(ADVICE_STATUS_HINTS)) | |
strbuf_addf(sb, _(" (use \"%s\" for details)\n"), | |
"git status --ahead-behind"); | |
} else if (!theirs) { | |
strbuf_addf(sb, | |
- Q_("Your branch is ahead of '%s' by %d commit.\n", | |
- "Your branch is ahead of '%s' by %d commits.\n", | |
+ Q_("Your branch is ahead of '%s' (as of %s) by %d commit.\n", | |
+ "Your branch is ahead of '%s' (as of %s) by %d commits.\n", | |
ours), | |
- base, ours); | |
+ base, as_of, ours); | |
if (advice_enabled(ADVICE_STATUS_HINTS)) | |
strbuf_addstr(sb, | |
_(" (use \"git push\" to publish your local commits)\n")); | |
} else if (!ours) { | |
strbuf_addf(sb, | |
- Q_("Your branch is behind '%s' by %d commit, " | |
+ Q_("Your branch is behind '%s' (as of %s) by %d commit, " | |
"and can be fast-forwarded.\n", | |
- "Your branch is behind '%s' by %d commits, " | |
+ "Your branch is behind '%s' (as of %s) by %d commits, " | |
"and can be fast-forwarded.\n", | |
theirs), | |
- base, theirs); | |
+ base, as_of, theirs); | |
if (advice_enabled(ADVICE_STATUS_HINTS)) | |
strbuf_addstr(sb, | |
_(" (use \"git pull\" to update your local branch)\n")); | |
} else { | |
strbuf_addf(sb, | |
- Q_("Your branch and '%s' have diverged,\n" | |
+ Q_("Your branch and '%s' (as of %s) have diverged,\n" | |
"and have %d and %d different commit each, " | |
"respectively.\n", | |
- "Your branch and '%s' have diverged,\n" | |
+ "Your branch and '%s' (as of %s) have diverged,\n" | |
"and have %d and %d different commits each, " | |
"respectively.\n", | |
ours + theirs), | |
- base, ours, theirs); | |
+ base, as_of, ours, theirs); | |
if (show_divergence_advice && | |
advice_enabled(ADVICE_STATUS_HINTS)) | |
strbuf_addstr(sb, | |
-- | |
2.25.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment