git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jiang Xin <worldhello.net@gmail.com>
Cc: Johannes Sixt <j6t@kdbg.org>, Git List <git@vger.kernel.org>
Subject: Re: [PATCH v15 03/16] quote.c: substitute path_relative with relative_path
Date: Wed, 26 Jun 2013 10:44:03 -0700	[thread overview]
Message-ID: <7vli5wwyvw.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <e1aa7e7d2e9ec1cd021ceffa7fd5cc4e858dd30b.1372175282.git.worldhello.net@gmail.com> (Jiang Xin's message of "Tue, 25 Jun 2013 23:53:44 +0800")

Jiang Xin <worldhello.net@gmail.com> writes:

> Substitute the function path_relative in quote.c with the function
> relative_path. Function relative_path can be treated as an enhanced
> and robust version of path_relative.
> ...
> And if prefix has no trailing slash, path_relative can not work properly
> either. But since prefix always has a trailing slash, so it's not a
> problem.

Nicely explained.

>  static void write_name(const char* name, size_t len)
>  {
> -	write_name_quoted_relative(name, len, prefix, prefix_len, stdout,
> -			line_terminator);
> +	/* Since prefix_len is ignored in write_name_quoted_relative, we
> +	 * should turn off prefix here in case of running "git ls-files"
> +	 * with "--full-name" option */
> +	write_name_quoted_relative(name, len, prefix_len ? prefix : NULL,
> +			prefix_len, stdout, line_terminator);
>  }

I'd tweak this function and write_naem_quoted_relative(), and
explain the reason for doing so in the log message.  Please check
what I'll push out on 'pu' later today.

-- >8 --
Subject: [PATCH] fix write_name() and write_name_quoted_relative() signature

The write_name_quoted_relative() function used to accept its two
parameters as counted strings.  Since it now uses relative_path(),
which requires both input strings to be NUL-terminated, the API of
this function need to be audited carefully.

Luckily, the only one caller is write_name() in builtin/ls-files.c,
and it in turn has only three callers.  They pass the string to be
made relative at this function and all of these strings happen to be
NUL terminated.  We can safely lose "len" parameter of write_name(),
and write_name_quoted_relative() can safely lose the length of its
name parameter as well.

The "prefix_len" parameter of write_name_quoted_relative() is either
0 (when "ls-files --full-name" is used), or the length of the prefix
string (i.e. the path to the current subdirectory).  By checking the
"--full-name" case in the caller, i.e. write_name(), we can make
write_name_quoted_relative() not to require the prefix as a counted
string.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/ls-files.c | 17 ++++++++---------
 quote.c            |  3 +--
 quote.h            |  5 ++---
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 247a8a4..d87e136 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -46,13 +46,12 @@ static const char *tag_modified = "";
 static const char *tag_skip_worktree = "";
 static const char *tag_resolve_undo = "";
 
-static void write_name(const char* name, size_t len)
+static void write_name(const char *name)
 {
-	/* Since prefix_len is ignored in write_name_quoted_relative, we
-	 * should turn off prefix here in case of running "git ls-files"
-	 * with "--full-name" option */
-	write_name_quoted_relative(name, len, prefix_len ? prefix : NULL,
-			prefix_len, stdout, line_terminator);
+	/* (prefix_len == 0) is for "--full-name" output */
+	write_name_quoted_relative(name,
+				   prefix_len ? prefix : NULL,
+				   stdout, line_terminator);
 }
 
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
@@ -66,7 +65,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
 		return;
 
 	fputs(tag, stdout);
-	write_name(ent->name, ent->len);
+	write_name(ent->name);
 }
 
 static void show_other_files(struct dir_struct *dir)
@@ -166,7 +165,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
 		       find_unique_abbrev(ce->sha1,abbrev),
 		       ce_stage(ce));
 	}
-	write_name(ce->name, ce_namelen(ce));
+	write_name(ce->name);
 	if (debug_mode) {
 		printf("  ctime: %d:%d\n", ce->ce_ctime.sec, ce->ce_ctime.nsec);
 		printf("  mtime: %d:%d\n", ce->ce_mtime.sec, ce->ce_mtime.nsec);
@@ -199,7 +198,7 @@ static void show_ru_info(void)
 			printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
 			       find_unique_abbrev(ui->sha1[i], abbrev),
 			       i + 1);
-			write_name(path, len);
+			write_name(path);
 		}
 	}
 }
diff --git a/quote.c b/quote.c
index 64ff344..6af3c83 100644
--- a/quote.c
+++ b/quote.c
@@ -312,8 +312,7 @@ void write_name_quotedpfx(const char *pfx, size_t pfxlen,
 	fputc(terminator, fp);
 }
 
-void write_name_quoted_relative(const char *name, size_t len,
-				const char *prefix, size_t prefix_len,
+void write_name_quoted_relative(const char *name, const char *prefix,
 				FILE *fp, int terminator)
 {
 	struct strbuf sb = STRBUF_INIT;
diff --git a/quote.h b/quote.h
index 133155a..8586bcd 100644
--- a/quote.h
+++ b/quote.h
@@ -60,9 +60,8 @@ extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
 extern void write_name_quoted(const char *name, FILE *, int terminator);
 extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,
                                  const char *name, FILE *, int terminator);
-extern void write_name_quoted_relative(const char *name, size_t len,
-		const char *prefix, size_t prefix_len,
-		FILE *fp, int terminator);
+extern void write_name_quoted_relative(const char *name, const char *prefix,
+				       FILE *fp, int terminator);
 
 /* quote path as relative to the given prefix */
 extern char *quote_path_relative(const char *in, int len,
-- 
1.8.3.1-773-g7e1bb7d

  reply	other threads:[~2013-06-26 17:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-25 15:53 [PATCH v15 00/16] Interactive git clean Jiang Xin
2013-06-25 15:53 ` [PATCH v15 01/16] test: add test cases for relative_path Jiang Xin
2013-06-26 17:44   ` Junio C Hamano
2013-06-27  1:00     ` Jiang Xin
2013-06-25 15:53 ` [PATCH v15 02/16] path.c: refactor relative_path(), not only strip prefix Jiang Xin
2013-06-26 17:44   ` Junio C Hamano
2013-06-27  3:31     ` Jiang Xin
2013-06-25 15:53 ` [PATCH v15 03/16] quote.c: substitute path_relative with relative_path Jiang Xin
2013-06-26 17:44   ` Junio C Hamano [this message]
2013-06-25 15:53 ` [PATCH v15 04/16] Refactor quote_path_relative, remove unused params Jiang Xin
2013-06-26 17:47   ` Junio C Hamano
2013-06-27  1:47     ` Jiang Xin
2013-06-25 15:53 ` [PATCH v15 05/16] Refactor write_name_quoted_relative, " Jiang Xin
2013-06-25 15:53 ` [PATCH v15 06/16] git-clean: refactor git-clean into two phases Jiang Xin
2013-06-25 15:53 ` [PATCH v15 07/16] git-clean: add support for -i/--interactive Jiang Xin
2013-06-25 15:53 ` [PATCH v15 08/16] git-clean: show items of del_list in columns Jiang Xin
2013-06-25 15:53 ` [PATCH v15 09/16] git-clean: add colors to interactive git-clean Jiang Xin
2013-06-25 15:53 ` [PATCH v15 10/16] git-clean: use a git-add-interactive compatible UI Jiang Xin
2013-06-25 15:53 ` [PATCH v15 11/16] git-clean: add filter by pattern interactive action Jiang Xin
2013-06-25 15:53 ` [PATCH v15 12/16] git-clean: add select by numbers " Jiang Xin
2013-06-25 15:53 ` [PATCH v15 13/16] git-clean: add ask each " Jiang Xin
2013-06-25 15:53 ` [PATCH v15 14/16] git-clean: add documentation for interactive git-clean Jiang Xin
2013-06-25 15:53 ` [PATCH v15 15/16] test: add t7301 for git-clean--interactive Jiang Xin
2013-06-25 15:53 ` [PATCH v15 16/16] test: run testcases with POSIX absolute paths on Windows Jiang Xin
2013-06-26 18:03 ` [PATCH v15 00/16] Interactive git clean Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vli5wwyvw.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=worldhello.net@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).