                           filename (trim (first all-lines))]
                       (if (some matching-line-in? changes) filename)))))))
 
-;; Return a newest-first sequence of revision numbers in which the item changed.
+;; Return a newest-first sequence of revision numbers in which the object
+;; changed.
 
-(defn revlist [item]
-  (let [logstream (java.io.ByteArrayInputStream. (.getBytes (log item)))]
+(defn revlist [object]
+  (let [logstream (java.io.ByteArrayInputStream. (.getBytes (log object)))]
     (for [e (try
               (xml-seq (parse logstream))
               (catch Exception e (errmsg)))

;; Print usage information.

(defn usage []
  (println (str "\nUsage: revdiff item [regex]\n"))
  (println "  item  : svn uri or name of versioned working-copy object")
  (println "  regex : only show diffs where a changed line matches regex\n"))

;; If item is a uri, the "-rn:m" revision-range format will not work if item is
;; no longer present in the head revision, in which case we have to use the
;; "item@n item@m" revision-specification format. Return the correctly formatted
;; versioned-path(s) string for use by a diff command.

(defn vpaths [r1 r2 path item]
  (if (uri? item)
    (list (str path "@" r1) (str path "@" r2))
    (list (str "-r" r1 ":" r2) path)))

(defn -main [& args]
  (let [item (first args) filt (or (second args) ".*")]
    (if (not item)
      (usage)
      (do
        (diffrevpairs item filt (revpairs (revlist item) item))
        (shutdown-agents)))))

;; Return a sequence of revision pairs for potential comparison -- e.g. for the
;; revlist (9 8 6 4 1), return (8 9 6 8 4 6 1 4).

(defn revpairs [revlist object]
  (when (seq (rest revlist))
    (concat (list (first (rest revlist)) (first revlist))
            (revpairs (rest revlist) object))))

;; WRITE NEW COMMENT HERE

(defn svndiff [r1 r2 filename object]
  (let [object (baseobject object)
        r (re-pattern (str "^.*/" filename "$"))
        p (if (uri? object)
            (if (re-matches r object) object (str object "/" filename))
            filename)
        v (vpaths r1 r2 p object)]
    (sh "svn" "diff" (first v) (second v))))

;; Is path a uri? If it contains :// assume it is.
