All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Johannes Schindelin <johannes.schindelin@gmx.de>
Cc: git@vger.kernel.org, gitster@pobox.com,
	Steffen Prohaska <prohaska@zib.de>
Subject: Re: [PATCH 1/2] Introduce the function strip_path_suffix()
Date: Wed, 18 Feb 2009 20:39:19 +0100	[thread overview]
Message-ID: <499C63E7.5040306@kdbg.org> (raw)
In-Reply-To: <7b5ee74d497bbb7144b8683725cd83c8bbd33f9a.1234969572u.git.johannes.schindelin@gmx.de>

Johannes Schindelin schrieb:
> The function strip_path_suffix() will try to split the given path into
> prefix/suffix.  The suffix has to be passed to the function, and if the
> path matches, the prefix is set.
> 
> Arbitrary runs of directory separators ("slashes") are assumed identical.
> 
> Example:
> 
> 	strip_path_suffix("C:\\msysgit/\\libexec\\git-core",
> 		"libexec///git-core", &prefix)
> 
> will set prefix to "C:\\msysgit" and return 0.

But you implemented it so that prefix is actually "C:\\msysgit/\\" 
(unless, of course, I'm reading the code wrong).

> +/* sets prefix if the suffix matches */
> +int strip_path_suffix(const char *path, const char *suffix, const char **prefix)

For a general purpose function, the API is very unnatural (and geared 
towards its only user in patch 2/2). I'd expect that the return value is 
the result or NULL on failure.

I would not raise this concern if this were a static function near its 
only call site.

> +{
> +	int path_len = strlen(path), suffix_len = strlen(suffix);
> +
> +	while (suffix_len) {
> +		if (!path_len)
> +			return 1;
> +
> +		if (is_dir_sep(path[path_len - 1])) {
> +			if (!is_dir_sep(suffix[suffix_len - 1]))
> +				return 1;
> +			path_len = chomp_trailing_dir_sep(path, path_len);
> +			suffix_len = chomp_trailing_dir_sep(suffix, suffix_len);
> +		}
> +		else if (path[--path_len] != suffix[--suffix_len])
> +			return 1;
> +	}
> +
> +	if (path_len && !is_dir_sep(path[path_len - 1]))
> +		return 1;

Should strip_path_suffix("foo/bar", "foo/bar", &prefix) succeed and 
prefix be the empty string? This implementation says it should be so. 
That's just a question...

> +	*prefix = xstrndup(path, chomp_trailing_dir_sep(path, path_len));
> +	return 0;
> +}

-- Hannes

  reply	other threads:[~2009-02-18 19:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-18 15:10 [PATCH 0/2] RUNTIME_PREFIX enhancements Johannes Schindelin
2009-02-18 15:11 ` [PATCH 1/2] Introduce the function strip_path_suffix() Johannes Schindelin
2009-02-18 19:39   ` Johannes Sixt [this message]
2009-02-18 21:13     ` Johannes Schindelin
2009-02-18 22:27       ` Johannes Sixt
2009-02-18 23:18         ` Johannes Schindelin
2009-02-19 19:10     ` [PATCH v2 0/2] RUNTIME_PREFIX enhancements Johannes Schindelin
2009-02-19 19:10     ` [PATCH v2 1/2] Introduce the function strip_path_suffix() Johannes Schindelin
2009-02-19 20:12       ` Johannes Schindelin
2009-02-19 20:26       ` Johannes Sixt
2009-02-19 20:44         ` Johannes Schindelin
2009-02-19 19:10     ` [PATCH v2 2/2] system_path(): simplify using strip_path_suffix(), and add suffix "git" Johannes Schindelin
2009-02-19 20:39       ` Johannes Sixt
2009-02-19 20:48         ` Johannes Schindelin
2009-02-20  8:35         ` Junio C Hamano
2009-02-18 15:11 ` [PATCH " Johannes Schindelin
2009-02-18 19:38 ` [PATCH 0/2] RUNTIME_PREFIX enhancements Johannes Sixt
2009-02-18 21:11   ` Johannes Schindelin
2009-02-18 22:52     ` Johannes Sixt
2009-02-18 23:19       ` Johannes Schindelin

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=499C63E7.5040306@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=prohaska@zib.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.