From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: Re: [PATCH 1/4] config --show-origin: report paths with forward slashes Date: Tue, 22 Mar 2016 10:58:18 -0700 Message-ID: References: <8beb1c208e33e1de8f272caa22fb7a0b662ca4cc.1458668543.git.johannes.schindelin@gmx.de> Mime-Version: 1.0 Content-Type: text/plain Cc: git@vger.kernel.org, Lars Schneider , Johannes Sixt , Kazutoshi SATODA , Eric Wong To: Johannes Schindelin X-From: git-owner@vger.kernel.org Tue Mar 22 18:58:26 2016 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aiQZV-0006N5-JC for gcvg-git-2@plane.gmane.org; Tue, 22 Mar 2016 18:58:25 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759467AbcCVR6W (ORCPT ); Tue, 22 Mar 2016 13:58:22 -0400 Received: from pb-smtp0.pobox.com ([208.72.237.35]:60134 "EHLO sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751212AbcCVR6U (ORCPT ); Tue, 22 Mar 2016 13:58:20 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id D64A14EDCA; Tue, 22 Mar 2016 13:58:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=jpxLroyUPCOxKf4mV/QNMwSjfyk=; b=HGp8g4 3u4ENSFG567Z2kjOVVXYZX0Lwo+nYUJh/X85ZoO9LKX4GnYKJVWuDlg+woWIPCK7 bZ5Y/XTNdsQtlAfGCmb1GRrTynUfB5d8pj2N3jHyds6fSERrCDWlnXBxsaPwaYfQ q1+MxOjwwQOEkyfLSFdlVO6QbKkQvZNMpP4WA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=Jk9qmGC0/7WBoabFjA1zIfj41b5nuXRS ySvajPYjieCGmEK99bnwG+BQ8ZKFg6Cd9DpUvr2XINuyRscIvKvGuArumCDMY53t TBy6y0tdhY3YzugbyuBmrrS+5P4Vp7+jncdHWiWOYlbCen51ereIfeOqUWVfDP/X A7EBnH/SbA4= Received: from pb-smtp0.int.icgroup.com (unknown [127.0.0.1]) by pb-smtp0.pobox.com (Postfix) with ESMTP id CDF244EDC9; Tue, 22 Mar 2016 13:58:19 -0400 (EDT) Received: from pobox.com (unknown [104.132.1.64]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by pb-smtp0.pobox.com (Postfix) with ESMTPSA id 4E0774EDC2; Tue, 22 Mar 2016 13:58:19 -0400 (EDT) In-Reply-To: <8beb1c208e33e1de8f272caa22fb7a0b662ca4cc.1458668543.git.johannes.schindelin@gmx.de> (Johannes Schindelin's message of "Tue, 22 Mar 2016 18:42:40 +0100 (CET)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Pobox-Relay-ID: A907AA16-F057-11E5-8BFB-79226BB36C07-77302942!pb-smtp0.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Johannes Schindelin writes: > On Windows, the backslash is the native directory separator, but > all supported Windows versions also accept the forward slash in > most circumstances. > > Our tests expect forward slashes. > > Relative paths are generated by Git using forward slashes. ... and the paths tracked by Git (in the index) use slashes. > So let's try to be consistent and use forward slashes in the $HOME > part of the paths reported by `git config --show-origin`, too. OK, sounds sensible. > > Signed-off-by: Johannes Schindelin > --- > compat/mingw.h | 6 ++++++ > path.c | 3 +++ > 2 files changed, 9 insertions(+) > > diff --git a/compat/mingw.h b/compat/mingw.h > index 8c5bf50..c008694 100644 > --- a/compat/mingw.h > +++ b/compat/mingw.h > @@ -396,6 +396,12 @@ static inline char *mingw_find_last_dir_sep(const char *path) > ret = (char *)path; > return ret; > } > +static inline void convert_slashes(char *path) > +{ > + for (; *path; path++) > + if (*path == '\\') > + *path = '/'; > +} > #define find_last_dir_sep mingw_find_last_dir_sep > int mingw_offset_1st_component(const char *path); > #define offset_1st_component mingw_offset_1st_component > diff --git a/path.c b/path.c > index 8b7e168..969b494 100644 > --- a/path.c > +++ b/path.c > @@ -584,6 +584,9 @@ char *expand_user_path(const char *path) > if (!home) > goto return_null; > strbuf_addstr(&user_path, home); > +#ifdef GIT_WINDOWS_NATIVE > + convert_slashes(user_path.buf); > +#endif Hmm, I wonder if we want to do this at a bit lower level, e.g. 1. have a fallback for other platforms in git-compat-util.h #ifndef get_HOME #define get_HOME() getenv("HOME") #endif 2. have the one that does convert-slashes for mingw static inline const char *mingw_getenv_HOME(void) { ... do convert-slashes on the result of getenv("HOME"); } #define get_HOME() mingw_getenv_HOME() 3. Instead of the above patch to path.c, change the line before the precontext with s/getenv("HOME")/get_HOME()/ Or even lower, inside mingw_getenv() and catch variables that deal with paths (not just HOME but PATH, TMP, TMPDIR, etc.) > } else { > struct passwd *pw = getpw_str(username, username_len); > if (!pw)