From 346c9344094635edbcf85ac6ddb27b8235038d8a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 16 Feb 2012 14:26:53 -0400 Subject: [PATCH] allow pathdepth to drop from the front or take from the end (negative) --- Command/AddUrl.hs | 9 ++++----- doc/git-annex.mdwn | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 9867369438..0b41310677 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -90,13 +90,12 @@ url2file :: URI -> Maybe Int -> FilePath url2file url pathdepth = case pathdepth of Nothing -> filesize $ escape fullurl Just depth - | depth > 0 -> filesize $ join "/" $ - fromend depth $ map escape $ - filter (not . null) $ split "/" fullurl - | otherwise -> error "bad --pathdepth value" + | depth > 0 -> frombits $ drop depth + | otherwise -> frombits $ reverse . take (negate depth) . reverse where fullurl = uriRegName auth ++ uriPath url ++ uriQuery url + frombits a = filesize $ join "/" $ a urlbits + urlbits = map escape $ filter (not . null) $ split "/" fullurl auth = fromMaybe (error $ "bad url " ++ show url) $ uriAuthority url filesize = take 255 escape = replace "/" "_" . replace "?" "_" - fromend n = reverse . take n . reverse diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index d5814a2c24..f13baf79ca 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -150,9 +150,10 @@ subdirectories). To avoid immediately downloading the url, specify --fast. Normally the filename is based on the full url, so will look like - "www.example.com_subdir_bigfile". For a shorter filename, specify + "www.example.com_dir_subdir_bigfile". For a shorter filename, specify --pathdepth=N. For example, --pathdepth=2 will use "subdir/bigfile", - while --parhdepth=1 will use "bigfile". + while --pathdepth=3 will use "bigfile". It can also be negative; + --pathdepth=-2 will use the last two parts of the url. Or, to directly specify what file the url is added to, specify --file. This changes the behavior; now all the specified urls are recorded as