Skip to content

Commit

Permalink
Allow IObjs to be cmp. to non IObjs when merging.
Browse files Browse the repository at this point in the history
Fixes #1110.
  • Loading branch information
hypirion committed Mar 27, 2013
1 parent c42bb2a commit 664da4a
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions leiningen-core/src/leiningen/core/project.clj
Expand Up @@ -63,15 +63,31 @@
(into [(symbol group-id artifact-id) version]))
(with-meta (meta dep)))))

(defn- meta*
"Returns the metadata of an object, or nil if the object cannot hold
metadata."
[obj]
(if (instance? clojure.lang.IObj obj)
(meta obj)
nil))

(defn- with-meta*
"Returns an object of the same type and value as obj, with map m as its
metadata if the object can hold metadata."
[obj m]
(if (instance? clojure.lang.IObj obj)
(with-meta obj m)
obj))

(defn- displace?
"Returns true if the object is marked as displaceable"
[obj]
(-> obj meta :displace))
(-> obj meta* :displace))

(defn- replace?
"Returns true if the object is marked as replaceable"
[obj]
(-> obj meta :replace))
(-> obj meta* :replace))

(defn- different-priority?
"Returns true if either left has a higher priority than right or vice versa."
Expand All @@ -88,25 +104,25 @@

(and (displace? left) ;; Pick the rightmost
(displace? right)) ;; if both are marked as displaceable
(with-meta right
(merge (meta left) (meta right)))
(with-meta* right
(merge (meta* left) (meta* right)))

(and (replace? left) ;; Pick the rightmost
(replace? right)) ;; if both are marked as replaceable
(with-meta right
(merge (meta left) (meta right)))
(with-meta* right
(merge (meta* left) (meta* right)))

(or (displace? left)
(replace? right))
(with-meta right
(merge (-> left meta (dissoc :displace))
(-> right meta (dissoc :replace))))
(with-meta* right
(merge (-> left meta* (dissoc :displace))
(-> right meta* (dissoc :replace))))

(or (replace? left)
(displace? right))
(with-meta left
(merge (-> right meta (dissoc :displace))
(-> left meta (dissoc :replace))))))
(with-meta* left
(merge (-> right meta* (dissoc :displace))
(-> left meta* (dissoc :replace))))))

(declare meta-merge)

Expand Down

0 comments on commit 664da4a

Please sign in to comment.