contrib/mercurial.el
changeset 2316 3d58376a7103
parent 1371 68e84563c540
child 2317 6d0a9de9a8ac
equal deleted inserted replaced
2314:e9b5749e4de3 2316:3d58376a7103
   388 			   (and path (file-name-directory path))
   388 			   (and path (file-name-directory path))
   389 			   nil nil
   389 			   nil nil
   390 			   (and path (file-name-nondirectory path))
   390 			   (and path (file-name-nondirectory path))
   391 			   'hg-file-history))
   391 			   'hg-file-history))
   392 	path))))
   392 	path))))
       
   393 
       
   394 (defun hg-read-number (&optional prompt default)
       
   395   "Read a integer value."
       
   396   (save-excursion
       
   397     (if (or (not default) current-prefix-arg)
       
   398         (string-to-number
       
   399          (eval (list* 'read-string
       
   400                       (or prompt "") 
       
   401                       (if default (cons (format "%d" default) nil) nil))))
       
   402       default)))
   393 
   403 
   394 (defun hg-read-config ()
   404 (defun hg-read-config ()
   395   "Return an alist of (key . value) pairs of Mercurial config data.
   405   "Return an alist of (key . value) pairs of Mercurial config data.
   396 Each key is of the form (section . name)."
   406 Each key is of the form (section . name)."
   397   (let (items)
   407   (let (items)
   948   (goto-char (point-min))
   958   (goto-char (point-min))
   949   (when (looking-at "^searching for changes")
   959   (when (looking-at "^searching for changes")
   950     (kill-entire-line))
   960     (kill-entire-line))
   951   (run-hooks 'hg-log-mode-hook))
   961   (run-hooks 'hg-log-mode-hook))
   952 
   962 
   953 (defun hg-log (path &optional rev1 rev2)
   963 (defun hg-log (path &optional rev1 rev2 log-limit)
   954   "Display the revision history of PATH, between REV1 and REV2.
   964   "Display the revision history of PATH.
   955 REV1 defaults to hg-log-limit changes from the tip revision, while
   965 History is displayed between REV1 and REV2.
   956 REV2 defaults to the tip.
   966 Number of displayed changesets is limited to LOG-LIMIT.
       
   967 REV1 defaults to the tip, while
       
   968 REV2 defaults to `hg-rev-completion-limit' changes from the tip revision.
       
   969 LOG-LIMIT defaults to `hg-log-limit'.
   957 With a prefix argument, prompt for each parameter."
   970 With a prefix argument, prompt for each parameter."
   958   (interactive (list (hg-read-file-name " to log")
   971   (interactive (list (hg-read-file-name " to log")
   959 		     (hg-read-rev " to start with" "-1")
   972                      (hg-read-rev " to start with"
   960 		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
   973                                   "tip")
       
   974                      (hg-read-rev " to end with"
       
   975                                   (format "%d" (- hg-rev-completion-limit)))
       
   976                      (hg-read-number "Output limited to: "
       
   977                                      hg-log-limit)))
   961   (let ((a-path (hg-abbrev-file-name path))
   978   (let ((a-path (hg-abbrev-file-name path))
   962 	(r1 (or rev1 (format "-%d" hg-log-limit)))
   979         (r1 (or rev1 (format "-%d" hg-rev-completion-limit)))
   963 	(r2 (or rev2 rev1 "-1")))
   980         (r2 (or rev2 rev1 "tip"))
       
   981         (limit (format "%d" (or log-limit hg-log-limit))))
   964     (hg-view-output ((if (equal r1 r2)
   982     (hg-view-output ((if (equal r1 r2)
   965 			 (format "Mercurial: Log of rev %s of %s" rev1 a-path)
   983                          (format "Mercurial: Log of rev %s of %s" rev1 a-path)
   966 		       (format "Mercurial: Log from rev %s to %s of %s"
   984                        (format 
   967 			       r1 r2 a-path)))
   985                         "Mercurial: at most %s log(s) from rev %s to %s of %s"
   968       (let ((revs (format "%s:%s" r1 r2)))
   986                         limit r1 r2 a-path)))
   969 	(if (> (length path) (length (hg-root path)))
   987       (eval (list* 'call-process (hg-binary) nil t nil
   970 	    (call-process (hg-binary) nil t nil "log" "-r" revs path)
   988                    "log"
   971 	  (call-process (hg-binary) nil t nil "log" "-r" revs)))
   989                    "-r" (format "%s:%s" r1 r2)
       
   990                    "-l" limit
       
   991                    (if (> (length path) (length (hg-root path)))
       
   992                        (cons path nil)
       
   993                      nil)))
   972       (hg-log-mode))))
   994       (hg-log-mode))))
   973 
   995 
   974 (defun hg-log-repo (path &optional rev1 rev2)
   996 (defun hg-log-repo (path &optional rev1 rev2 log-limit)
   975   "Display the revision history of the repository containing PATH.
   997   "Display the revision history of the repository containing PATH.
   976 History is displayed between REV1, which defaults to the tip, and
   998 History is displayed between REV1 and REV2.
   977 REV2, which defaults to the initial revision.
   999 Number of displayed changesets is limited to LOG-LIMIT,
   978 Variable hg-log-limit controls the number of log entries displayed."
  1000 REV1 defaults to the tip, while
       
  1001 REV2 defaults to `hg-rev-completion-limit' changes from the tip revision.
       
  1002 LOG-LIMIT defaults to `hg-log-limit'.
       
  1003 With a prefix argument, prompt for each parameter."
   979   (interactive (list (hg-read-file-name " to log")
  1004   (interactive (list (hg-read-file-name " to log")
   980 		     (hg-read-rev " to start with" "tip")
  1005                      (hg-read-rev " to start with"
   981 		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
  1006                                   "tip")
   982   (hg-log (hg-root path) rev1 rev2))
  1007                      (hg-read-rev " to end with" 
       
  1008                                   (format "%d" (- hg-rev-completion-limit)))
       
  1009                      (hg-read-number "Output limited to: "
       
  1010                                      hg-log-limit)))
       
  1011   (hg-log (hg-root path) rev1 rev2 log-limit))
   983 
  1012 
   984 (defun hg-outgoing (&optional repo)
  1013 (defun hg-outgoing (&optional repo)
   985   "Display changesets present locally that are not present in REPO."
  1014   "Display changesets present locally that are not present in REPO."
   986   (interactive (list (hg-read-repo-name " where changes would go to" nil
  1015   (interactive (list (hg-read-repo-name " where changes would go to" nil
   987 					hg-outgoing-repository)))
  1016 					hg-outgoing-repository)))