summaryrefslogtreecommitdiff
path: root/Utility/Path.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2020-05-04 15:38:39 -0400
committerJoey Hess <joeyh@joeyh.name>2020-05-04 15:38:39 -0400
commit8c4352a0a544b2e5a4ed717999fc7c6ecb0a328f (patch)
treed57aca56117598b06bf30e5a1ed96f4b77e51f09 /Utility/Path.hs
parent6ea7eac330f73699d965cef7b8ee23d7218415a8 (diff)
downloadgit-repair-8c4352a0a544b2e5a4ed717999fc7c6ecb0a328f.tar.gz
merge from git-annex
* Improve fetching from a remote with an url in host:path format. * Merge from git-annex.
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r--Utility/Path.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs
index ecc752c..a8ab918 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -41,7 +41,7 @@ import Prelude
import Utility.Monad
import Utility.UserInfo
-import Utility.Directory
+import Utility.SystemDirectory
import Utility.Split
import Utility.FileSystemEncoding
@@ -74,6 +74,8 @@ simplifyPath path = dropTrailingPathSeparator $
{- Makes a path absolute.
-
+ - Also simplifies it using simplifyPath.
+ -
- The first parameter is a base directory (ie, the cwd) to use if the path
- is not already absolute, and should itsef be absolute.
-
@@ -124,12 +126,19 @@ dirContains a b = a == b
{- Converts a filename into an absolute path.
-
+ - Also simplifies it using simplifyPath.
+ -
- Unlike Directory.canonicalizePath, this does not require the path
- already exists. -}
absPath :: FilePath -> IO FilePath
-absPath file = do
- cwd <- getCurrentDirectory
- return $ absPathFrom cwd file
+absPath file
+ -- Avoid unncessarily getting the current directory when the path
+ -- is already absolute. absPathFrom uses simplifyPath
+ -- so also used here for consistency.
+ | isAbsolute file = return $ simplifyPath file
+ | otherwise = do
+ cwd <- getCurrentDirectory
+ return $ absPathFrom cwd file
{- Constructs a relative path from the CWD to a file.
-