mercurial.el: add hg-cwd
authorBryan O'Sullivan <bos@serpentine.com>
Tue, 22 Aug 2006 14:03:10 -0700
changeset 3003 78fe7e2c2e1e
parent 3002 65efeb7b2c56
child 3004 ac74046f8f58
mercurial.el: add hg-cwd
contrib/mercurial.el
--- a/contrib/mercurial.el	Tue Aug 22 14:02:43 2006 -0700
+++ b/contrib/mercurial.el	Tue Aug 22 14:03:10 2006 -0700
@@ -1211,6 +1211,21 @@
 	root)
     hg-root))
 
+(defun hg-cwd (&optional path)
+  "Return the current directory of PATH within the repository."
+  (do ((stack nil (cons (file-name-nondirectory
+			 (directory-file-name dir))
+			stack))
+       (prev nil dir)
+       (dir (file-name-directory (or path buffer-file-name
+				     (expand-file-name default-directory)))
+	    (file-name-directory (directory-file-name dir))))
+      ((equal prev dir))
+    (when (file-directory-p (concat dir ".hg"))
+      (let ((cwd (mapconcat 'identity stack "/")))
+	(unless (equal cwd "")
+	  (return (file-name-as-directory cwd)))))))
+
 (defun hg-status (path)
   "Print revision control status of a file or directory.
 With prefix argument, prompt for the path to give status for.