ZyX_I avatar ZyX_I committed e84d2f5

@aurum: Made :AuJunk, :AuMove and :AuTrack accept directory arguments (untested)
Should fix ref #13 (won’t mark as fixed untill I add tests)

Comments (0)

Files changed (3)

     - Two or more arguments with last one that is a name of existing 
       directory: move files matching given patterns (all arguments but the 
       last one) to given directory (last argument).
+      You may also specify unexisting directory with trailing forward slash. 
+      In this case it will be created.
     - One or more arguments that have not matched any of the above rules: move 
       files matching given patterns (patterns are all arguments) to the 
       current directory.
     normalized form, they just should be accepted by VCS.
   update :: hex, force                                       *aurum-rf-update*
     Update working directory to changeset {hex}.
-  move :: force, file, file -> _                               *aurum-rf-move*
-  copy :: force, file, file -> _                               *aurum-rf-copy*
-    Move or copy given file (second argument) to given destination (third 
-    argument).
-  forget :: file -> _                                        *aurum-rf-forget*
-  remove :: file -> _                                        *aurum-rf-remove*
-  add    :: file -> _                                        *aurum-rf-add*
-  ignore :: file -> _                                        *aurum-rf-ignore*
+  move :: force, fdir, file -> _                               *aurum-rf-move*
+  copy :: force, fdir, file -> _                               *aurum-rf-copy*
+    Move or copy given file or directory (second argument) to given 
+    destination (third argument).
+    Note: directories are always passed with trailing forward slash.
+  forget :: fdir -> _                                        *aurum-rf-forget*
+  remove :: fdir -> _                                        *aurum-rf-remove*
+  add    :: fdir -> _                                        *aurum-rf-add*
+  ignore :: fdir -> _                                        *aurum-rf-ignore*
     Forget, remove, add (make tracked) or ignore (add to .hgignore or 
-    something similar) given file. “ignore” function properly escapes file if 
-    it happen to contain any wildcards.
+    something similar) given file or directory. “ignore” function properly 
+    escapes file if it happen to contain any wildcards.
+    Note: directories are always passed with trailing forward slash.
   ignoreglob :: glob -> _                                *aurum-rf-ignoreglob*
     Add given glob to .hgignore or similar.
                                                                *aurum-rf-grep*
 endfunction
 "▶1 filterfiles
 function s:F.filterfiles(repo, globs, files)
+    if empty(a:globs)
+        return []
+    endif
     let r=[]
-    for pattern in map(copy(a:globs), 's:_r.globtopat('.
-                \                     'a:repo.functions.reltorepo(a:repo, '.
-                \                                                'v:val))')
-        let r+=filter(copy(a:files), 'v:val=~#pattern && index(r, v:val)==-1')
+    let dirs={}
+    for file in a:files
+        let fsplit=split(file, '\V/')
+        if empty(fsplit)
+            continue
+        endif
+        let d=dirs
+        for component in fsplit[:-2]
+            let component.='/'
+            if !has_key(d, component)
+                let d[component]={}
+            endif
+            let d=d[component]
+        endfor
+        let d[fsplit[-1]]=1
     endfor
+    unlet d
+    let patterns=map(copy(a:globs), 's:_r.globtopat('.
+                \                   'a:repo.functions.reltorepo(a:repo,v:val))')
+    let tocheck=map(items(dirs), '[v:val[1], v:val[0]]')
+    while !empty(tocheck)
+        let [d, f]=remove(tocheck, 0)
+        if !empty(filter(copy(patterns), 'f=~#v:val'))
+            let r+=[f]
+        elseif f[-1:] is# '/'
+            let tocheck+=map(items(d), '[v:val[1], f.v:val[0]]')
+        endif
+        unlet d
+    endwhile
     return r
 endfunction
 "▶1 urlescape :: String → String
     else
         let globs=filter(copy(a:000), 'v:val isnot# ":"')
         let hascur=(len(globs)!=a:0)
-        if a:0==1 || !isdirectory(globs[-1])
+        if a:0==1 || !(isdirectory(globs[-1]) && globs[-1][-1:] isnot# '/')
             let target='.'
         else
             let target=remove(globs, -1)
+            if !isdirectory(target)
+                call mkdir(target, 'p')
+            endif
         endif
         let files=s:F.filterfiles(repo, globs, allfiles)
         if hascur
 :CS show all
 :W{{{1 :AuJ *
 :R silent edit hglines.lst
-:R AuJunk *
+:R silent AuJunk *
 :CS
 :source addmessages.vim
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.