changeset 3003:78fe7e2c2e1e

mercurial.el: add hg-cwd
author Bryan O'Sullivan <bos@serpentine.com>
date Tue, 22 Aug 2006 14:03:10 -0700
parents 65efeb7b2c56
children ac74046f8f58
files contrib/mercurial.el
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.