From: Dan Nicolaescu Date: Thu, 21 Jun 2007 05:44:54 +0000 (+0000) Subject: Add to do items. X-Git-Tag: emacs-pretest-23.0.90~12183 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cdaf01cce1ef3efe4a6198eda484a28a1ee9534b;p=emacs.git Add to do items. (vc-hg-diff): Add support for comparing different revisions. (vc-hg-diff, vc-hg-annotate-command, vc-hg-annotate-time) (vc-hg-annotate-extract-revision-at-line) (vc-hg-previous-version, vc-hg-checkin): New functions. (vc-hg-annotate-re): New constant. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c2d25f1ca30..5df52f8f0b8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2007-06-21 Dan Nicolaescu + + * vc-hg.el: Add to do items. + (vc-hg-diff): Add support for comparing different revisions. + (vc-hg-diff, vc-hg-annotate-command, vc-hg-annotate-time) + (vc-hg-annotate-extract-revision-at-line) + (vc-hg-previous-version, vc-hg-checkin): New functions. + (vc-hg-annotate-re): New constant. + 2007-06-20 Jay Belanger * calc/calc.el (math-standard-ops): Fix precedence of diff --git a/lisp/vc-hg.el b/lisp/vc-hg.el index d1ad447b9b9..c7bcda7ebc5 100644 --- a/lisp/vc-hg.el +++ b/lisp/vc-hg.el @@ -35,7 +35,10 @@ ;;; Todo: -;; Implement the rest of the vc interface +;; Implement the rest of the vc interface: +;; - regexps for log-view to understand the "hg log" output +;; - dired +;; - snapshot? ;; Implement Stefan Monnier's advice: ;; vc-hg-registered and vc-hg-state @@ -108,15 +111,53 @@ (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) file "log")) -(defun vc-hg-diff (file &optional oldvers newvers buffers) +(defun vc-hg-diff (file &optional oldvers newvers buffer) "Get a difference report using hg between two versions of FILE." - (when buffers (message buffers)) - (unless buffers (setq buffers "*vc-diff*")) - (when oldvers (message oldvers)) - (when newvers (message newvers)) - (call-process "hg" nil buffers nil - "--cwd" (file-name-directory file) - "diff" (file-name-nondirectory file))) + (let ((working (vc-workfile-version file))) + (if (and (equal oldvers working) (not newvers)) + (setq oldvers nil)) + (if (and (not oldvers) newvers) + (setq oldvers working)) + (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil + "--cwd" (file-name-directory file) "diff" + (append + (if oldvers + (if newvers + (list "-r" oldvers "-r" newvers) + (list "-r" oldvers)) + (list "")) + (list (file-name-nondirectory file)))))) + +(defun vc-hg-annotate-command (file buffer &optional version) + "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. +Optional arg VERSION is a version to annotate from." + (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) + (with-current-buffer buffer + (goto-char (point-min)) + (re-search-forward "^[0-9]") + (delete-region (point-min) (1- (point))))) + + +;;; The format for one line output by "hg annotate -d -n" looks like this: +;;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS +;;; i.e: VERSION_NUMBER DATE: CONTENTS +(defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ") + +(defun vc-hg-annotate-time () + (when (looking-at vc-hg-annotate-re) + (goto-char (match-end 0)) + (vc-annotate-convert-time + (date-to-time (match-string-no-properties 2))))) + +(defun vc-hg-annotate-extract-revision-at-line () + (save-excursion + (beginning-of-line) + (if (looking-at vc-hg-annotate-re) (match-string-no-properties 1)))) + +(defun vc-hg-previous-version (file rev) + (let ((newrev (1- (string-to-number rev)))) + (when (>= newrev 0) + (number-to-string newrev)))) (defun vc-hg-register (file &optional rev comment) "Register FILE under hg. @@ -124,6 +165,11 @@ REV is ignored. COMMENT is ignored." (vc-hg-command nil nil file "add")) +(defun vc-hg-checkin (file rev comment) + "HG-specific version of `vc-backend-checkin'. +REV is ignored." + (vc-hg-command nil nil file "commit" "-m" comment)) + ;;; Modelled after the similar function in vc-bzr.el (defun vc-hg-checkout (file &optional editable rev workfile) "Retrieve a revision of FILE into a WORKFILE.