diff options
-rw-r--r-- | Command/AddUrl.hs | 37 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | doc/git-annex.mdwn | 13 |
3 files changed, 36 insertions, 15 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 981af2f7e..a6c89542e 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -22,34 +22,40 @@ import qualified Option import Types.Key def :: [Command] -def = [withOptions [fileOption] $ +def = [withOptions [fileOption, pathdepthOption] $ command "addurl" (paramRepeating paramUrl) seek "add urls to annex"] fileOption :: Option fileOption = Option.field [] "file" paramFile "specify what file the url is added to" +pathdepthOption :: Option +pathdepthOption = Option.field [] "pathdepth" paramFile "number of path components to use in filename" + seek :: [CommandSeek] seek = [withField fileOption return $ \f -> - withStrings $ start f] + withField pathdepthOption (return . maybe Nothing readish) $ \d -> + withStrings $ start f d] -start :: Maybe FilePath -> String -> CommandStart -start optfile s = notBareRepo $ go $ fromMaybe bad $ parseURI s +start :: Maybe FilePath -> Maybe Int -> String -> CommandStart +start optfile pathdepth s = notBareRepo $ go $ fromMaybe bad $ parseURI s where bad = fromMaybe (error $ "bad url " ++ s) $ parseURI $ escapeURIString isUnescapedInURI s go url = do - let file = fromMaybe (url2file url) optfile + let file = fromMaybe (url2file url pathdepth) optfile showStart "addurl" file - next $ perform s file + next $ perform s file pathdepth -perform :: String -> FilePath -> CommandPerform -perform url file = ifAnnexed file addurl geturl +perform :: String -> FilePath -> Maybe Int -> CommandPerform +perform url file pathdepth = ifAnnexed file addurl geturl where geturl = do liftIO $ createDirectoryIfMissing True (parentDir file) fast <- Annex.getState Annex.fast if fast then nodownload url file else download url file addurl (key, _backend) = do + when (pathdepth /= Nothing) $ + error $ file ++ " already exists" unlessM (liftIO $ Url.check url (keySize key)) $ error $ "failed to verify url: " ++ url setUrlPresent key url @@ -80,8 +86,17 @@ nodownload url file = do setUrlPresent key url next $ Command.Add.cleanup file key False -url2file :: URI -> FilePath -url2file url = take 255 $ escape $ uriRegName auth ++ uriPath url ++ uriQuery url +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" where - escape = replace "/" "_" . replace "?" "_" + fullurl = uriRegName auth ++ uriPath url ++ uriQuery url auth = fromMaybe (error $ "bad url " ++ show url) $ uriAuthority url + filesize = take 255 + escape = replace "/" "_" . replace "?" "_" + fromend n = reverse . take n . reverse diff --git a/debian/changelog b/debian/changelog index dc792a6e7..9ca875217 100644 --- a/debian/changelog +++ b/debian/changelog @@ -29,6 +29,7 @@ git-annex (3.20120124) UNRELEASED; urgency=low * whereis: Prints the urls of files that the web special remote knows about. * Added a annex.queuesize setting, useful when adding hundreds of thousands of files on a system with plenty of memory. + * addurl: Add --pathdepth option. -- Joey Hess <joeyh@debian.org> Tue, 24 Jan 2012 16:21:55 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index d4e62568f..d5814a2c2 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -149,10 +149,15 @@ subdirectories). To avoid immediately downloading the url, specify --fast. - To specify what file the url is added to, specify --file. This changes - the behavior; now all the specified urls are recorded as alternate - locations from which the file can be downloaded. In this mode, addurl - can be used both to add new files, or to add urls to existing files. + Normally the filename is based on the full url, so will look like + "www.example.com_subdir_bigfile". For a shorter filename, specify + --pathdepth=N. For example, --pathdepth=2 will use "subdir/bigfile", + while --parhdepth=1 will use "bigfile". + + 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 + alternate locations from which the file can be downloaded. In this mode, + addurl can be used both to add new files, or to add urls to existing files. # REPOSITORY SETUP COMMANDS |