Skip to content

Commit 459d35d

Browse files
Richard NewmanRichard Newman
Richard Newman
authored and
Richard Newman
committed
Alter how tree rows are represented. We now use a 4-element vector rather than a map, and can now take permissions as input to make-tree. This is a breaking change.
1 parent b3ff612 commit 459d35d

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object store.
4444

4545
;; Make a tree and commit it.
4646
user=> (with-repo "/tmp/raw"
47-
(make-tree [["5dd01c177f5d7d1be5346a5bc18a569a7410c2ef" "blob" "some-file"]]))
47+
(make-tree [[nil "blob" "5dd01c177f5d7d1be5346a5bc18a569a7410c2ef" "some-file"]]))
4848
"1a4d231af53de9164b03296a4dcc18e2fcd715c6"
4949

5050
user=> (with-repo "/tmp/raw"

src/com/twinql/clojure/git.clj

+18-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(sh "mkdir" "-p" dir)
2727
(with-sh-dir dir
2828
(sh "git" "init")))
29-
29+
3030
(defn status []
3131
(sh "git" "status"))
3232

@@ -65,23 +65,24 @@
6565
(when (not filters?) ["--no-filters"]))))))
6666

6767
(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."
6970
[entries]
7071
(chomp
7172
(sh :in (apply str
7273
(seq
73-
(map (fn [[sha1 kind name]]
74+
(map (fn [[perms kind sha1 name]]
7475
(let [k (git-kind kind)]
7576
(cond
7677
;; TODO: how do I handle tags and commits?
7778
(= k "tag")
78-
(str "040000 tag " sha1 \tab name \newline)
79+
(str (or perms "040000") " tag " sha1 \tab name \newline)
7980
(= k "commit")
80-
(str "040000 commit " sha1 \tab name \newline)
81+
(str (or perms "040000") " commit " sha1 \tab name \newline)
8182
(= k "tree")
82-
(str "040000 tree " sha1 \tab name \newline)
83+
(str (or perms "040000") " tree " sha1 \tab name \newline)
8384
(= k "blob")
84-
(str "100644 blob " sha1 \tab name \newline))))
85+
(str (or perms "100644") " blob " sha1 \tab name \newline))))
8586
entries)))
8687
"git" "mktree")))
8788

@@ -132,7 +133,13 @@
132133
:type type
133134
:object sha1
134135
: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+
136143
(defn commit->tree
137144
[commit]
138145
(when commit
@@ -149,10 +156,10 @@
149156
(if (nil? tree)
150157
(throw (new Exception "nil passed to ls-tree."))
151158
(with-line-seq [s (sh "git" "ls-tree" tree)]
152-
(doall (map tree-entry->map s))))))
159+
(doall (map tree-entry-seq s))))))
153160

154161
(defn blob? [x]
155-
(= "blob" (:type x)))
162+
(= "blob" (second x)))
156163

157164
(defn tree-contents
158165
"Not lazy to avoid any problems with bindings 'expiring'.
@@ -161,7 +168,7 @@
161168
([tree filt]
162169
(into {}
163170
(map (fn [x]
164-
[(:name x) (cat-object (:object x))])
171+
[(nth x 3) (cat-object (nth x 2))])
165172
(filter filt (ls-tree tree)))))
166173
([tree]
167174
(tree-contents tree (constantly true))))

0 commit comments

Comments
 (0)