|
26 | 26 | (sh "mkdir" "-p" dir)
|
27 | 27 | (with-sh-dir dir
|
28 | 28 | (sh "git" "init")))
|
29 |
| - |
| 29 | + |
30 | 30 | (defn status []
|
31 | 31 | (sh "git" "status"))
|
32 | 32 |
|
|
65 | 65 | (when (not filters?) ["--no-filters"]))))))
|
66 | 66 |
|
67 | 67 | (defn make-tree
|
68 |
| - "Each entry is a sequence of SHA1, kind, name." |
| 68 | + "Each entry is a sequence of perms, kind, SHA1, name. |
| 69 | + If perms is nil, the default will be used for the kind." |
69 | 70 | [entries]
|
70 | 71 | (chomp
|
71 | 72 | (sh :in (apply str
|
72 | 73 | (seq
|
73 |
| - (map (fn [[sha1 kind name]] |
| 74 | + (map (fn [[perms kind sha1 name]] |
74 | 75 | (let [k (git-kind kind)]
|
75 | 76 | (cond
|
76 | 77 | ;; TODO: how do I handle tags and commits?
|
77 | 78 | (= k "tag")
|
78 |
| - (str "040000 tag " sha1 \tab name \newline) |
| 79 | + (str (or perms "040000") " tag " sha1 \tab name \newline) |
79 | 80 | (= k "commit")
|
80 |
| - (str "040000 commit " sha1 \tab name \newline) |
| 81 | + (str (or perms "040000") " commit " sha1 \tab name \newline) |
81 | 82 | (= k "tree")
|
82 |
| - (str "040000 tree " sha1 \tab name \newline) |
| 83 | + (str (or perms "040000") " tree " sha1 \tab name \newline) |
83 | 84 | (= k "blob")
|
84 |
| - (str "100644 blob " sha1 \tab name \newline)))) |
| 85 | + (str (or perms "100644") " blob " sha1 \tab name \newline)))) |
85 | 86 | entries)))
|
86 | 87 | "git" "mktree")))
|
87 | 88 |
|
|
132 | 133 | :type type
|
133 | 134 | :object sha1
|
134 | 135 | :name filename}))
|
135 |
| - |
| 136 | + |
| 137 | +(defn tree-entry-seq |
| 138 | + "Returns a 4-element sequence for an ls-tree row: |
| 139 | + perms type object filename" |
| 140 | + [e] |
| 141 | + (rest (re-matches #"^([0-9]{6}) ([a-z]+) ([0-9a-f]+{40})\t(.*)$" e))) |
| 142 | + |
136 | 143 | (defn commit->tree
|
137 | 144 | [commit]
|
138 | 145 | (when commit
|
|
149 | 156 | (if (nil? tree)
|
150 | 157 | (throw (new Exception "nil passed to ls-tree."))
|
151 | 158 | (with-line-seq [s (sh "git" "ls-tree" tree)]
|
152 |
| - (doall (map tree-entry->map s)))))) |
| 159 | + (doall (map tree-entry-seq s)))))) |
153 | 160 |
|
154 | 161 | (defn blob? [x]
|
155 |
| - (= "blob" (:type x))) |
| 162 | + (= "blob" (second x))) |
156 | 163 |
|
157 | 164 | (defn tree-contents
|
158 | 165 | "Not lazy to avoid any problems with bindings 'expiring'.
|
|
161 | 168 | ([tree filt]
|
162 | 169 | (into {}
|
163 | 170 | (map (fn [x]
|
164 |
| - [(:name x) (cat-object (:object x))]) |
| 171 | + [(nth x 3) (cat-object (nth x 2))]) |
165 | 172 | (filter filt (ls-tree tree)))))
|
166 | 173 | ([tree]
|
167 | 174 | (tree-contents tree (constantly true))))
|
|
0 commit comments