contrib/mercurial.el
changeset 996 5ed566574486
parent 995 1e4b009b379e
child 999 bb391518bc28
equal deleted inserted replaced
995:1e4b009b379e 996:5ed566574486
   512   (interactive)
   512   (interactive)
   513   (hg-view-output ("Mercurial Help Overview")
   513   (hg-view-output ("Mercurial Help Overview")
   514     (insert (documentation 'hg-help-overview))))
   514     (insert (documentation 'hg-help-overview))))
   515 
   515 
   516 (defun hg-add (path)
   516 (defun hg-add (path)
       
   517   "Add PATH to the Mercurial repository on the next commit.
       
   518 With a prefix argument, prompt for the path to add."
   517   (interactive (list (hg-read-file-name " to add")))
   519   (interactive (list (hg-read-file-name " to add")))
   518   (let ((buf (current-buffer))
   520   (let ((buf (current-buffer))
   519 	(update (equal buffer-file-name path)))
   521 	(update (equal buffer-file-name path)))
   520     (hg-view-output (hg-output-buffer-name)
   522     (hg-view-output (hg-output-buffer-name)
   521       (apply 'call-process (hg-binary) nil t nil (list "add" path)))
   523       (apply 'call-process (hg-binary) nil t nil (list "add" path)))
   534 (defun hg-commit ()
   536 (defun hg-commit ()
   535   (interactive)
   537   (interactive)
   536   (error "not implemented"))
   538   (error "not implemented"))
   537 
   539 
   538 (defun hg-diff (path &optional rev1 rev2)
   540 (defun hg-diff (path &optional rev1 rev2)
       
   541   "Show the differences between REV1 and REV2 of PATH.
       
   542 When called interactively, the default behaviour is to treat REV1 as
       
   543 the tip revision, REV2 as the current edited version of the file, and
       
   544 PATH as the file edited in the current buffer.
       
   545 With a prefix argument, prompt for all of these."
   539   (interactive (list (hg-read-file-name " to diff")
   546   (interactive (list (hg-read-file-name " to diff")
   540 		     (hg-read-rev " to start with")
   547 		     (hg-read-rev " to start with")
   541 		     (let ((rev2 (hg-read-rev " to end with" 'working-dir)))
   548 		     (let ((rev2 (hg-read-rev " to end with" 'working-dir)))
   542 		       (and (not (eq rev2 'working-dir)) rev2))))
   549 		       (and (not (eq rev2 'working-dir)) rev2))))
   543   (unless rev1
   550   (unless rev1
   555       (setq diff (not (= (point-min) (point-max))))
   562       (setq diff (not (= (point-min) (point-max))))
   556       (font-lock-fontify-buffer))
   563       (font-lock-fontify-buffer))
   557     diff))
   564     diff))
   558 
   565 
   559 (defun hg-forget (path)
   566 (defun hg-forget (path)
       
   567   "Lose track of PATH, which has been added, but not yet committed.
       
   568 This will prevent the file from being incorporated into the Mercurial
       
   569 repository on the next commit.
       
   570 With a prefix argument, prompt for the path to forget."
   560   (interactive (list (hg-read-file-name " to forget")))
   571   (interactive (list (hg-read-file-name " to forget")))
   561   (let ((buf (current-buffer))
   572   (let ((buf (current-buffer))
   562 	(update (equal buffer-file-name path)))
   573 	(update (equal buffer-file-name path)))
   563     (hg-view-output (hg-output-buffer-name)
   574     (hg-view-output (hg-output-buffer-name)
   564       (apply 'call-process (hg-binary) nil t nil (list "forget" path)))
   575       (apply 'call-process (hg-binary) nil t nil (list "forget" path)))
   573 (defun hg-init ()
   584 (defun hg-init ()
   574   (interactive)
   585   (interactive)
   575   (error "not implemented"))
   586   (error "not implemented"))
   576 
   587 
   577 (defun hg-log (path &optional rev1 rev2)
   588 (defun hg-log (path &optional rev1 rev2)
       
   589   "Display the revision history of PATH, between REV1 and REV2.
       
   590 REV1 defaults to the initial revision, while REV2 defaults to the tip.
       
   591 With a prefix argument, prompt for each parameter."
   578   (interactive (list (hg-read-file-name " to log")
   592   (interactive (list (hg-read-file-name " to log")
   579 		     (hg-read-rev " to start with" "-1")
   593 		     (hg-read-rev " to start with" "-1")
   580 		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
   594 		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
   581   (let ((a-path (hg-abbrev-file-name path)))
   595   (let ((a-path (hg-abbrev-file-name path)))
   582     (hg-view-output ((if (equal rev1 rev2)
   596     (hg-view-output ((if (equal rev1 rev2)
   607     (hg-restore-context ctx)
   621     (hg-restore-context ctx)
   608     (hg-mode-line)
   622     (hg-mode-line)
   609     (message "Reverting %s...done" buffer-file-name)))
   623     (message "Reverting %s...done" buffer-file-name)))
   610 
   624 
   611 (defun hg-revert-buffer ()
   625 (defun hg-revert-buffer ()
       
   626   "Revert current buffer's file back to the latest committed version.
       
   627 If the file has not changed, nothing happens.  Otherwise, this
       
   628 displays a diff and asks for confirmation before reverting."
   612   (interactive)
   629   (interactive)
   613   (let ((vc-suppress-confirm nil)
   630   (let ((vc-suppress-confirm nil)
   614 	(obuf (current-buffer))
   631 	(obuf (current-buffer))
   615 	diff)
   632 	diff)
   616     (vc-buffer-sync)
   633     (vc-buffer-sync)
   626     (set-buffer obuf)
   643     (set-buffer obuf)
   627     (when diff
   644     (when diff
   628       (hg-revert-buffer-internal))))
   645       (hg-revert-buffer-internal))))
   629 
   646 
   630 (defun hg-root (&optional path)
   647 (defun hg-root (&optional path)
       
   648   "Return the root of the repository that contains the given path.
       
   649 If the path is outside a repository, return nil.
       
   650 When called interactively, the root is printed.  A prefix argument
       
   651 prompts for a path to check."
   631   (interactive (list (hg-read-file-name)))
   652   (interactive (list (hg-read-file-name)))
   632   (let ((root (do ((prev nil dir)
   653   (let ((root (do ((prev nil dir)
   633 		   (dir (file-name-directory (or path (buffer-file-name)))
   654 		   (dir (file-name-directory (or path (buffer-file-name)))
   634 			(file-name-directory (directory-file-name dir))))
   655 			(file-name-directory (directory-file-name dir))))
   635 		  ((equal prev dir))
   656 		  ((equal prev dir))
   641 	(message "The path `%s' is not in a Mercurial repository."
   662 	(message "The path `%s' is not in a Mercurial repository."
   642 		 (abbreviate-file-name path t))))
   663 		 (abbreviate-file-name path t))))
   643     root))
   664     root))
   644 
   665 
   645 (defun hg-status (path)
   666 (defun hg-status (path)
       
   667   "Print revision control status of a file or directory.
       
   668 With prefix argument, prompt for the path to give status for.
       
   669 Names are displayed relative to the repository root."
   646   (interactive (list (hg-read-file-name " for status" (hg-root))))
   670   (interactive (list (hg-read-file-name " for status" (hg-root))))
   647   (let ((root (hg-root)))
   671   (let ((root (hg-root)))
   648     (hg-view-output (hg-output-buffer-name)
   672     (hg-view-output ((format "Mercurial: Status of %s in %s"
       
   673 			     (let ((name (substring (expand-file-name path)
       
   674 						    (length root))))
       
   675 			       (if (> (length name) 0)
       
   676 				   name
       
   677 				 "*"))
       
   678 			     (hg-abbrev-file-name root)))
   649       (apply 'call-process (hg-binary) nil t nil
   679       (apply 'call-process (hg-binary) nil t nil
   650 	     (list "--cwd" root "status" path)))))
   680 	     (list "--cwd" root "status" path)))))
   651 
   681 
   652 (defun hg-undo ()
   682 (defun hg-undo ()
   653   (interactive)
   683   (interactive)