git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 4/5] status: show worktree status of conflicted paths separately
Date: Wed,  5 Aug 2009 02:15:45 -0700	[thread overview]
Message-ID: <1249463746-21538-5-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1249463746-21538-4-git-send-email-gitster@pobox.com>

When a path is unmerged in the index, we used to always say "unmerged" in
the "Changed but not updated" section, even when the path was deleted in
the work tree.

Remove unmerged entries from the "Updated" section, and create a new
section "Unmerged paths".  Describe how the different stages conflict
in more detail in this new section.

Note that with the current 3-way merge policy (with or without recursive),
certain combinations of index stages should never happen.  For example,
having only stage #2 means that a path that did not exist in the common
ancestor was added by us while the other branch did not do anything to it,
which would have autoresolved to take our addition.  The code nevertheless
prepares for the possibility that future merge policies may leave a path
in such a state.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 wt-status.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 1614352..f73bf47 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -20,7 +20,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RED,    /* WT_STATUS_CHANGED */
 	GIT_COLOR_RED,    /* WT_STATUS_UNTRACKED */
 	GIT_COLOR_RED,    /* WT_STATUS_NOBRANCH */
-	GIT_COLOR_YELLOW, /* WT_STATUS_UNMERGED */
+	GIT_COLOR_RED,    /* WT_STATUS_UNMERGED */
 };
 
 enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
@@ -38,6 +38,8 @@ static int parse_status_slot(const char *var, int offset)
 		return WT_STATUS_UNTRACKED;
 	if (!strcasecmp(var+offset, "nobranch"))
 		return WT_STATUS_NOBRANCH;
+	if (!strcasecmp(var+offset, "unmerged"))
+		return WT_STATUS_UNMERGED;
 	die("bad config variable '%s'", var);
 }
 
@@ -60,6 +62,18 @@ void wt_status_prepare(struct wt_status *s)
 	s->change.strdup_strings = 1;
 }
 
+static void wt_status_print_unmerged_header(struct wt_status *s)
+{
+	const char *c = color(WT_STATUS_HEADER);
+	color_fprintf_ln(s->fp, c, "# Unmerged paths:");
+	if (!s->is_initial)
+		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
+	else
+		color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
+	color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to mark resolution)");
+	color_fprintf_ln(s->fp, c, "#");
+}
+
 static void wt_status_print_cached_header(struct wt_status *s)
 {
 	const char *c = color(WT_STATUS_HEADER);
@@ -100,6 +114,29 @@ static void wt_status_print_trailer(struct wt_status *s)
 
 #define quote_path quote_path_relative
 
+static void wt_status_print_unmerged_data(struct wt_status *s,
+					  struct string_list_item *it)
+{
+	const char *c = color(WT_STATUS_UNMERGED);
+	struct wt_status_change_data *d = it->util;
+	struct strbuf onebuf = STRBUF_INIT;
+	const char *one, *how = "bug";
+
+	one = quote_path(it->string, -1, &onebuf, s->prefix);
+	color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
+	switch (d->stagemask >> 1) {
+	case 1: how = "both deleted"; break;
+	case 2: how = "added by us"; break;
+	case 3: how = "deleted by them"; break;
+	case 4: how = "added by them"; break;
+	case 5: how = "deleted by us"; break;
+	case 6: how = "both added"; break;
+	case 7: how = "both modified"; break;
+	}
+	color_fprintf(s->fp, c, "%-20s: %s\n", how, one);
+	strbuf_release(&onebuf);
+}
+
 static void wt_status_print_change_data(struct wt_status *s,
 					int change_type,
 					struct string_list_item *it)
@@ -303,6 +340,29 @@ void wt_status_collect_changes(struct wt_status *s)
 		wt_status_collect_changes_index(s);
 }
 
+static void wt_status_print_unmerged(struct wt_status *s)
+{
+	int shown_header = 0;
+	int i;
+
+	for (i = 0; i < s->change.nr; i++) {
+		struct wt_status_change_data *d;
+		struct string_list_item *it;
+		it = &(s->change.items[i]);
+		d = it->util;
+		if (!d->stagemask)
+			continue;
+		if (!shown_header) {
+			wt_status_print_unmerged_header(s);
+			shown_header = 1;
+		}
+		wt_status_print_unmerged_data(s, it);
+	}
+	if (shown_header)
+		wt_status_print_trailer(s);
+
+}
+
 static void wt_status_print_updated(struct wt_status *s)
 {
 	int shown_header = 0;
@@ -364,7 +424,8 @@ static void wt_status_print_changed(struct wt_status *s)
 		struct string_list_item *it;
 		it = &(s->change.items[i]);
 		d = it->util;
-		if (!d->worktree_status)
+		if (!d->worktree_status ||
+		    d->worktree_status == DIFF_STATUS_UNMERGED)
 			continue;
 		wt_status_print_change_data(s, WT_STATUS_CHANGED, it);
 	}
@@ -505,6 +566,7 @@ void wt_status_print(struct wt_status *s)
 		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
 	}
 
+	wt_status_print_unmerged(s);
 	wt_status_print_updated(s);
 	wt_status_print_changed(s);
 	if (wt_status_submodule_summary)
-- 
1.6.4.18.g07a4a

  reply	other threads:[~2009-08-05  9:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05  9:15 [PATCH 0/5] Revamping "git status" Junio C Hamano
2009-08-05  9:15 ` [PATCH 1/5] diff-index: report unmerged new entries Junio C Hamano
2009-08-05  9:15   ` [PATCH 2/5] diff-index: keep the original index intact Junio C Hamano
2009-08-05  9:15     ` [PATCH 3/5] wt-status.c: rework the way changes to the index and work tree are summarized Junio C Hamano
2009-08-05  9:15       ` Junio C Hamano [this message]
2009-08-05  9:15         ` [PATCH 5/5] shortstatus: a new command Junio C Hamano
2009-08-06 15:33           ` Jeff King
2009-08-06 16:23             ` Breaking "git status" (was Re: [PATCH 5/5] shortstatus: a new command) Junio C Hamano
2009-08-06 16:42               ` Jeff King
2009-08-06 19:06                 ` Breaking "git status" Junio C Hamano
2009-08-06 19:57               ` Breaking "git status" (was Re: [PATCH 5/5] shortstatus: a new command) Sverre Rabbelier
2009-08-06 14:53         ` [PATCH 4/5] status: show worktree status of conflicted paths separately Jeff King
2009-08-06 14:46       ` [PATCH 3/5] wt-status.c: rework the way changes to the index and work tree are summarized Jeff King
2009-08-06 15:50         ` Junio C Hamano
2009-08-05  9:49 ` [PATCH 0/5] Revamping "git status" Thomas Rast
2009-08-05 16:57   ` Junio C Hamano
2009-08-05 17:37     ` Thomas Rast
2009-08-05 17:40       ` Thomas Rast
2009-08-05 18:05         ` Junio C Hamano
2009-08-05 18:52           ` Thomas Rast
2009-08-05 20:02             ` Junio C Hamano
2009-08-05 20:14               ` Thomas Rast

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=1249463746-21538-5-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.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).