wt-status: refactor detached HEAD analysis

wt_status_print() is the only caller of wt_status_get_detached_from(). The latter performs most of the analysis of a detached HEAD, including finding state->detached_from; the caller checks whether the detached HEAD is still at state->detached_from or has moved away. Move that last bit of analysis to wt_status_get_detached_from(), too, and store the boolean result in state->detached_at. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Mar 6, 2015 at 16:04 UTC 970399e74c14df4dc82f10e1fcd0f12531e9b305
2 files changed +4 -3
wt-status.c
+3 -3
@@ -1222,6 +1222,8 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1222 state->detached_from =
1223 xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));
1224 hashcpy(state->detached_sha1, cb.nsha1);
1225 + state->detached_at = !get_sha1("HEAD", sha1) &&
1226 + !hashcmp(sha1, state->detached_sha1);
1227
1228 free(ref);
1229 strbuf_release(&cb.buf);
@@ -1310,10 +1312,8 @@ void wt_status_print(struct wt_status *s)
1312 on_what = _("rebase in progress; onto ");
1313 branch_name = state.onto;
1314 } else if (state.detached_from) {
1313 - unsigned char sha1[20];
1315 branch_name = state.detached_from;
1315 - if (!get_sha1("HEAD", sha1) &&
1316 - !hashcmp(sha1, state.detached_sha1))
1316 + if (state.detached_at)
1317 on_what = _("HEAD detached at ");
1318 else
1319 on_what = _("HEAD detached from ");
wt-status.h
+1
@@ -84,6 +84,7 @@ struct wt_status_state {
84 int cherry_pick_in_progress;
85 int bisect_in_progress;
86 int revert_in_progress;
87 + int detached_at;
88 char *branch;
89 char *onto;
90 char *detached_from;