[PATCH] quote_path: convert empty path to "./"

Subsystems: the rest

DORMANTno replies

5 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] quote_path: convert empty path to "./"

From: Jeff King <hidden>
Date: 2016-06-15 22:43:57

Now that we are correctly removing leading prefixes from files in git
status, there is a degenerate case: the directory matching the prefix.
Because we show only the directory name for a directory that contains
only untracked files, it gets collapsed to an empty string.

Example:

  $ git init
  $ mkdir subdir
  $ touch subdir/file
  $ git status
  ...
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #       subdir/

  So far, so good.

  $ cd subdir
  $ git status
  ....
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #

  Oops, that's a bit confusing.

  This patch prints './' to show that there is some output.

---
I think it looks a bit ugly because it is so small (though just '.' was
even worse). But I don't see what else would make sense.

 wt-status.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 02dbb75..31d83bf 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -121,6 +121,9 @@ static char *quote_path(const char *in, int len,
 		}
 	}
 
+	if (!out->len)
+		strbuf_addstr(out, "./");
+
 	return out->buf;
 }
 
-- 
1.5.3.7.2156.g3d791-dirty

Re: [PATCH] quote_path: convert empty path to "./"

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:43:57

Hi,

On Fri, 7 Dec 2007, Jeff King wrote:
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #       subdir/

  So far, so good.

  $ cd subdir
  $ git status
  ....
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #

  Oops, that's a bit confusing.

  This patch prints './' to show that there is some output.
Sounds reasonable.

Ciao,
Dscho

Re: [PATCH] quote_path: convert empty path to "./"

From: Thomas Harning <hidden>
Date: 2016-06-15 22:43:57

Johannes Schindelin wrote:
Hi,

On Fri, 7 Dec 2007, Jeff King wrote:
  
quoted
...
    
Sounds reasonable.

Ciao,
Dscho  
I concur.  There is one case that this seems to dodge.  What about the 
case where you are in:

/test/test_2  where /test  is not tracked...

This should probably show "./../"   not just "./"   , right?

Re: [PATCH] quote_path: convert empty path to "./"

From: Jeff King <hidden>
Date: 2016-06-15 22:43:57

On Fri, Dec 07, 2007 at 02:05:15PM -0500, Thomas Harning wrote:
I concur.  There is one case that this seems to dodge.  What about the case 
where you are in:

/test/test_2  where /test  is not tracked...

This should probably show "./../"   not just "./"   , right?
It already says "../", which is correct:

  $ git init
  $ mkdir test && cd test
  $ touch file
  $ mkdir test2 && cd test2
  $ git status
  ...
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #       ../

There's no point in ever saying "./" _except_ in the case where the
output would be totally blank, since there is no way to tell that it is
an output line.

Personally, I don't like either the "../" or the "./", but I actually
think the relative paths are less readable than the full paths in
general.

-Peff

[PATCH] add status.relativePaths config variable

From: Jeff King <hidden>
Date: 2016-06-15 22:43:57

The output of git-status was recently changed to output
relative paths. Setting this variable to false restores the
old behavior for any old-timers that prefer it.

Signed-off-by: Jeff King <redacted>
---
On Fri, Dec 07, 2007 at 03:49:37PM -0500, Jeff King wrote:
Personally, I don't like either the "../" or the "./", but I actually
think the relative paths are less readable than the full paths in
general.
So here is a config option to turn it off; I don't think there should be
any consistency problems, since git-status output is meant to be
human-readable (and after all, we just changed it :) ).

This patch also contains a small buglet fix in the neighboring code
where we didn't stop trying to match "color.status.*" even after we used
it to set the status color.

 Documentation/config.txt |    6 ++++++
 builtin-commit.c         |    3 +--
 builtin-revert.c         |    2 +-
 t/t7502-status.sh        |   31 +++++++++++++++++++++++++++++++
 wt-status.c              |   10 +++++++++-
 wt-status.h              |    2 +-
 6 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index f0ffb9d..fabe7f8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -776,6 +776,12 @@ showbranch.default::
 	The default set of branches for gitlink:git-show-branch[1].
 	See gitlink:git-show-branch[1].
 
+status.relativePaths::
+	By default, gitlink:git-status[1] shows paths relative to the
+	current directory. Setting this variable to `false` shows paths
+	relative to the repository root (this was the default for git
+	prior to v1.5.4).
+
 tar.umask::
 	This variable can be used to restrict the permission bits of
 	tar archive entries.  The default is 0002, which turns off the
diff --git a/builtin-commit.c b/builtin-commit.c
index 18c6323..04b3bf1 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -284,8 +284,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix)
 {
 	struct wt_status s;
 
-	wt_status_prepare(&s);
-	s.prefix = prefix;
+	wt_status_prepare(&s, prefix);
 
 	if (amend) {
 		s.amend = 1;
diff --git a/builtin-revert.c b/builtin-revert.c
index 4bf8eb2..c285f8e 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -277,7 +277,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 
 		if (get_sha1("HEAD", head))
 			die ("You do not have a valid HEAD");
-		wt_status_prepare(&s);
+		wt_status_prepare(&s, NULL);
 		if (s.commitable)
 			die ("Dirty index: cannot %s", me);
 		discard_cache();
diff --git a/t/t7502-status.sh b/t/t7502-status.sh
index d6ae69d..9ce50ca 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -88,4 +88,35 @@ test_expect_success 'status with relative paths' '
 
 '
 
+cat > expect << \EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#	new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#	modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#	dir1/untracked
+#	dir2/modified
+#	dir2/untracked
+#	expect
+#	output
+#	untracked
+EOF
+
+test_expect_success 'status without relative paths' '
+
+	git config status.relativePaths false
+	(cd dir1 && git status) > output &&
+	git diff expect output
+
+'
+
 test_done
diff --git a/wt-status.c b/wt-status.c
index 02dbb75..b21b2c4 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -8,6 +8,7 @@
 #include "revision.h"
 #include "diffcore.h"
 
+int wt_status_relative_paths = 1;
 int wt_status_use_color = 0;
 static char wt_status_colors[][COLOR_MAXLEN] = {
 	"",         /* WT_STATUS_HEADER: normal */
@@ -42,7 +43,7 @@ static const char* color(int slot)
 	return wt_status_use_color ? wt_status_colors[slot] : "";
 }
 
-void wt_status_prepare(struct wt_status *s)
+void wt_status_prepare(struct wt_status *s, const char *prefix)
 {
 	unsigned char sha1[20];
 	const char *head;
@@ -53,6 +54,8 @@ void wt_status_prepare(struct wt_status *s)
 	s->reference = "HEAD";
 	s->fp = stdout;
 	s->index_file = get_index_file();
+	if (wt_status_relative_paths)
+		s->prefix = prefix;
 }
 
 static void wt_status_print_cached_header(struct wt_status *s)
@@ -397,6 +400,11 @@ int git_status_config(const char *k, const char *v)
 	if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
 		int slot = parse_status_slot(k, 13);
 		color_parse(v, k, wt_status_colors[slot]);
+		return 0;
+	}
+	if (!strcmp(k, "status.relativepaths")) {
+		wt_status_relative_paths = git_config_bool(k, v);
+		return 0;
 	}
 	return git_default_config(k, v);
 }
diff --git a/wt-status.h b/wt-status.h
index 225fb4d..0ed94f3 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -28,7 +28,7 @@ struct wt_status {
 
 int git_status_config(const char *var, const char *value);
 int wt_status_use_color;
-void wt_status_prepare(struct wt_status *s);
+void wt_status_prepare(struct wt_status *s, const char *prefix);
 void wt_status_print(struct wt_status *s);
 
 #endif /* STATUS_H */
-- 
1.5.3.7.2159.gde63a-dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help