markdown clojure实现git gc垃圾回收处理文件io clj文件处理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown clojure实现git gc垃圾回收处理文件io clj文件处理相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env lein-exec
;; This script goes through all git directories
;; recursively and executes "git gc" to each
;;
(import '(java.nio.file Path Paths Files))
(use '[clojure.java.shell :only (sh with-sh-dir)])
(defn resolve-path [name]
;; resolves a string to a `java.nio.file.Path`
(Paths/get name (into-array String [])))
(defn exists [path]
(Files/exists path (into-array java.nio.file.LinkOption [])))
(defn is-directory [path]
(Files/isDirectory path (into-array java.nio.file.LinkOption [])))
(defn git-dir [path]
;; simple check if the directory `path` is git managed
(and (is-directory path)
(exists (.resolve path "HEAD"))
(exists (.resolve path "objects"))
(exists (.resolve path "refs"))))
(defn list-dir [path]
;; list the contents of a given directory (Path)
(with-open [dirstream (Files/newDirectoryStream path)]
(vec (iterator-seq (.iterator dirstream)))))
(defn with-subdirs [path f]
;; applies `f` to `path` and every subdir
(f path)
(doseq [e (filter is-directory (list-dir path))] (with-subdirs e f)))
(defn git-gc [dir]
;;perform "git gc" command in `dir`
(when (git-dir dir)
(println (str "Perform git gc on " dir))
(with-sh-dir (str (.toAbsolutePath dir))
(sh "git" "gc"))))
(defn recur-git-gc [path]
(with-subdirs path git-gc))
;; -------------------------------------------------------------------------
(recur-git-gc (resolve-path (first (rest *command-line-args*))))
以上是关于markdown clojure实现git gc垃圾回收处理文件io clj文件处理的主要内容,如果未能解决你的问题,请参考以下文章
Xamarin.Android AndroidEnvironment文件未应用于更改GC Bridge实现
markdown Clojure clj中协议和记录的简要示例
markdown rss中的关键词统计来自clojure的快乐
markdown Clojure中Java类的漂亮打印方法。在REPL中有用。
markdown 列表交叉合并类似Python中的zip功能(clojure clj ruby scala map vector list)
MAC记住 git的用户名密码