|
14 | 14 | (:refer-clojure :exclude [resolve])
|
15 | 15 | (:require
|
16 | 16 | [clojure.java.io :as jio]
|
| 17 | + [clojure.tools.gitlibs.config :as config] |
17 | 18 | [clojure.tools.gitlibs.impl :as impl]))
|
18 | 19 |
|
19 | 20 | (set! *warn-on-reflection* true)
|
|
22 | 23 | "Return the root gitlibs cache directory. By default ~/.gitlibs or
|
23 | 24 | override by setting the environment variable GITLIBS."
|
24 | 25 | []
|
25 |
| - (impl/cache-dir)) |
| 26 | + (:gitlibs/dir @config/CONFIG)) |
26 | 27 |
|
27 | 28 | ;; Possible new API, internal for now
|
28 | 29 | (defn- resolve-all
|
29 | 30 | "Takes a git url and a coll of revs, and returns the full commit shas.
|
30 | 31 | Each rev may be a partial sha, full sha, or tag name. Returns nil for
|
31 |
| - unresolveable revs. |
32 |
| -
|
33 |
| - Optional opts map may include: |
34 |
| - :interactive (default false) - set true to allow stdin prompts (example: unknown host) |
35 |
| - :print-commands (default false) - set true to write git executions to stderr" |
36 |
| - ([url revs] |
37 |
| - (resolve-all url revs nil)) |
38 |
| - ([url revs opts] |
39 |
| - (let [git-dir (impl/ensure-git-dir url opts)] |
40 |
| - (reduce |
41 |
| - (fn [rs r] |
42 |
| - (if-let [res (impl/git-rev-parse git-dir r opts)] |
43 |
| - (conj rs res) |
44 |
| - (do ;; could not resolve - fetch and try again |
45 |
| - (impl/git-fetch (jio/file git-dir) opts) |
46 |
| - (conj rs (impl/git-rev-parse git-dir r opts))))) |
47 |
| - [] revs)))) |
| 32 | + unresolveable revs." |
| 33 | + [url revs] |
| 34 | + (let [git-dir (impl/ensure-git-dir url)] |
| 35 | + (reduce |
| 36 | + (fn [rs r] |
| 37 | + (if-let [res (impl/git-rev-parse git-dir r)] |
| 38 | + (conj rs res) |
| 39 | + (do ;; could not resolve - fetch and try again |
| 40 | + (impl/git-fetch (jio/file git-dir)) |
| 41 | + (conj rs (impl/git-rev-parse git-dir r))))) |
| 42 | + [] revs))) |
48 | 43 |
|
49 | 44 | (defn resolve
|
50 | 45 | "Takes a git url and a rev, and returns the full commit sha or nil if can't
|
51 |
| - resolve. rev may be a partial sha, full sha, or tag name. |
52 |
| -
|
53 |
| - Optional opts map may include: |
54 |
| - :interactive (default false) - set true to allow stdin prompts (example: unknown host) |
55 |
| - :print-commands (default false) - set true to write git executions to stderr" |
56 |
| - ([url rev] |
57 |
| - (resolve url rev nil)) |
58 |
| - ([url rev opts] |
59 |
| - (first (resolve-all url [rev] opts)))) |
| 46 | + resolve. rev may be a partial sha, full sha, or tag name." |
| 47 | + [url rev] |
| 48 | + (first (resolve-all url [rev]))) |
60 | 49 |
|
61 | 50 | (defn procure
|
62 | 51 | "Procure a working tree at rev for the git url representing the library lib,
|
63 | 52 | returns the directory path. lib is a qualified symbol where the qualifier is a
|
64 |
| - controlled or conveyed identity, or nil if rev is unknown. |
65 |
| -
|
66 |
| - Optional opts map may include: |
67 |
| - :interactive (default false) - set true to allow stdin prompts (example: unknown host) |
68 |
| - :print-commands (default false) - set true to write git commands to stderr" |
69 |
| - ([url lib rev] |
70 |
| - (procure url lib rev nil)) |
71 |
| - ([url lib rev opts] |
72 |
| - (let [lib-dir (impl/lib-dir lib) |
73 |
| - git-dir-path (impl/ensure-git-dir url opts) |
74 |
| - sha (or (impl/match-exact lib-dir rev) (impl/match-prefix lib-dir rev) (resolve url rev))] |
75 |
| - (when sha |
76 |
| - (let [sha-dir (jio/file lib-dir sha)] |
77 |
| - (when-not (.exists sha-dir) |
78 |
| - (impl/printerrln "Checking out:" url "at" rev) |
79 |
| - (impl/git-checkout git-dir-path lib-dir sha opts)) |
80 |
| - (.getCanonicalPath sha-dir)))))) |
| 53 | + controlled or conveyed identity, or nil if rev is unknown." |
| 54 | + [url lib rev] |
| 55 | + (let [lib-dir (impl/lib-dir lib) |
| 56 | + git-dir-path (impl/ensure-git-dir url) |
| 57 | + sha (or (impl/match-exact lib-dir rev) (impl/match-prefix lib-dir rev) (resolve url rev))] |
| 58 | + (when sha |
| 59 | + (let [sha-dir (jio/file lib-dir sha)] |
| 60 | + (when-not (.exists sha-dir) |
| 61 | + (impl/printerrln "Checking out:" url "at" rev) |
| 62 | + (impl/git-checkout git-dir-path lib-dir sha)) |
| 63 | + (.getCanonicalPath sha-dir))))) |
81 | 64 |
|
82 | 65 | (defn descendant
|
83 | 66 | "Returns rev in git url which is a descendant of all other revs,
|
84 |
| - or nil if no such relationship can be established. |
85 |
| -
|
86 |
| - Optional opts map may include: |
87 |
| - :interactive (default false) - set true to allow stdin prompts (example: unknown host) |
88 |
| - :print-commands (default false) - set true to write git commands to stderr" |
89 |
| - ([url rev] |
90 |
| - (descendant url rev nil)) |
91 |
| - ([url revs opts] |
92 |
| - (when (seq revs) |
93 |
| - (let [shas (resolve-all url revs opts)] |
94 |
| - (if (seq (filter nil? shas)) |
95 |
| - nil ;; can't resolve all shas in this repo |
96 |
| - (let [git-dir (impl/ensure-git-dir url opts)] |
97 |
| - (->> shas (sort (partial impl/commit-comparator git-dir opts)) first))))))) |
| 67 | + or nil if no such relationship can be established." |
| 68 | + [url revs] |
| 69 | + (when (seq revs) |
| 70 | + (let [shas (resolve-all url revs)] |
| 71 | + (if (seq (filter nil? shas)) |
| 72 | + nil ;; can't resolve all shas in this repo |
| 73 | + (let [git-dir (impl/ensure-git-dir url)] |
| 74 | + (->> shas (sort (partial impl/commit-comparator git-dir)) first)))))) |
98 | 75 |
|
99 | 76 | (defn tags
|
100 | 77 | "Returns coll of tags in git url"
|
|
104 | 81 | (impl/tags (impl/ensure-git-dir url opts) opts)))
|
105 | 82 |
|
106 | 83 | (comment
|
107 |
| - ( resolve "[email protected]:clojure/tools.gitlibs.git" "11fc774" { :print-commands true :interactive true}) |
108 |
| - (descendant "https://github.com/clojure/tools.gitlibs.git" ["5e2797a487c" "11fc774" "d82adc29" "815e312310"] {:print-commands true}) |
| 84 | + (System/setProperty "clojure.gitlibs.debug" "true") |
| 85 | + ( resolve "[email protected]:clojure/tools.gitlibs.git" "11fc774") |
| 86 | + (descendant "https://github.com/clojure/tools.gitlibs.git" ["5e2797a487c" "11fc774" "d82adc29" "815e312310"]) |
109 | 87 |
|
110 | 88 | (println
|
111 | 89 | @(future (procure "https://github.com/clojure/tools.gitlibs.git" 'org.clojure/tools.gitlibs "11fc77496f013871c8af3514bbba03de0af28061"))
|
|
0 commit comments