Git config --show-origin paths look funny...

333 views
Skip to first unread message

Lars Schneider

unread,
Feb 27, 2016, 2:04:18 PM2/27/16
to git-for-windows
Hi,

my "git config" flag "--show-origin" arrived on Git master:

Since I got my Git for Windows working nicely (great SDK!) I tried it right away:


As you can see the paths look funny ("\\" and sometimes "/"). Is there anything we could do about this (I have not much experience with Git for Windows)?


Thanks,

Lars


Duy Nguyen

unread,
Feb 27, 2016, 8:22:50 PM2/27/16
to Lars Schneider, git-for-windows
On Sat, Feb 27, 2016 at 11:04:18AM -0800, Lars Schneider wrote:
> Hi,
>
> my "git config" flag "--show-origin" arrived on Git master:
> https://github.com/git/git/commit/dd0f567f1041a3caea7856b3efe20f8fb9b487b5
>
> Since I got my Git for Windows working nicely (great SDK!) I tried it right
> away:
>
> <https://lh3.googleusercontent.com/-GdI10yoVYb4/VtHyt42TpzI/AAAAAAAAAjg/t-Iz0kqXP3I/s1600/Screen%2BShot%2B2016-02-27%2Bat%2B19.55.05.png>
>
>
> As you can see the paths look funny ("\\" and sometimes "/"). Is there
> anything we could do about this (I have not much experience with Git for
> Windows)?

Path given by Windows use the backward slashes while Git code always
generates forward slashes (even though it accepts both as path
separator). Something like this may work, the idea is rewrite output
paths. It's like translating strings to different languages, if you
consider Windows paths a "language".

I will not follow this up because I don't use Windows (I changed
#ifdef to #ifndef to test it). If you are interested in making paths
on Windows look better, I suggest you check with both GFW and Git
community on the approach before start making more changes.

-- 8< --
diff --git a/builtin/config.c b/builtin/config.c
index ca9f834..694c555 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -94,6 +94,34 @@ static void check_argc(int argc, int min, int max) {
usage_with_options(builtin_config_usage, builtin_config_options);
}

+#ifdef GIT_WINDOWS_NATIVE
+static const char *P_(const char *p)
+{
+ static struct strbuf buf[4] = {
+ STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
+ };
+ static int idx;
+ struct strbuf *sb;
+ int i;
+
+ if (!strchr(p, '/'))
+ return p;
+ sb = buf + idx;
+ idx = (idx + 1) % 4;
+ strbuf_reset(sb);
+ strbuf_addstr(sb, p);
+ for (i = 0; i < sb->len; i++)
+ if (sb->buf[i] == '/')
+ sb->buf[i] = '\\';
+ return sb->buf;
+}
+#else
+static inline const char *P_(const char *p)
+{
+ return p;
+}
+#endif
+
static void show_config_origin(struct strbuf *buf)
{
const char term = end_null ? '\0' : '\t';
@@ -101,9 +129,9 @@ static void show_config_origin(struct strbuf *buf)
strbuf_addstr(buf, current_config_origin_type());
strbuf_addch(buf, ':');
if (end_null)
- strbuf_addstr(buf, current_config_name());
+ strbuf_addstr(buf, P_(current_config_name()));
else
- quote_c_style(current_config_name(), buf, NULL, 0);
+ quote_c_style(P_(current_config_name()), buf, NULL, 0);
strbuf_addch(buf, term);
}
-- 8< --

Reply all
Reply to author
Forward
0 new messages