From 7eed858cac7e8ff78626bdc5d63a7f36ca8f8010 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Mar 2015 16:33:51 +0200 Subject: Move roots and bases to appropriate scopes --- build/diagnostics.cxx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'build/diagnostics.cxx') diff --git a/build/diagnostics.cxx b/build/diagnostics.cxx index 34bbee8..f5802de 100644 --- a/build/diagnostics.cxx +++ b/build/diagnostics.cxx @@ -21,14 +21,31 @@ namespace build if (p == work) return "."; - path rp (relative_work (p)); +#ifndef _WIN32 + if (p == home) + return "~"; +#endif + + path rw (relative_work (p)); #ifndef _WIN32 - if (rp.absolute () && rp.sub (home)) - return "~/" + rp.leaf (home).string (); + if (rw.relative ()) + { + // See if the original path with the ~/ shortcut is better + // that the relative to work. + // + if (p.sub (home)) + { + path rh (p.leaf (home)); + if (rw.string ().size () > rh.string ().size () + 2) // 2 for '~/' + return "~/" + rh.string (); + } + } + else if (rw.sub (home)) + return "~/" + rw.leaf (home).string (); #endif - return rp.string (); + return rw.string (); } return p.string (); -- cgit v1.1