1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

Improve handling of the first Git revision

* lisp/vc/log-view.el (log-view-toggle-entry-display): When
there's no next entry, delete until the end of the buffer.
(log-view-end-of-defun-1): Stop at eob.

* lisp/vc/vc-annotate.el
(vc-annotate-show-diff-revision-at-line-internal): Don't give up
when previous-revision is nil.

* lisp/vc/vc-git.el (vc-git-expanded-log-entry): End the arguments
with `--' to avoid ambiguity.
(vc-git-annotate-extract-revision-at-line): Exclude `^' from the
returned revision string.
(vc-git-annotate-time): Expect `^' before the first revision.

* lisp/vc/vc-git.el (vc-git-diff): Diff against an empty tree if
REV1 is nil, and REV2 is not.

* lisp/vc/vc.el: Update the description of the `diff' function.
This commit is contained in:
Dmitry Gutov 2015-05-18 15:49:13 +03:00
parent d3d50a9c99
commit 69d24b40d2
4 changed files with 30 additions and 21 deletions

View file

@ -404,7 +404,9 @@ This calls `log-view-expanded-log-entry-function' to do the work."
(unless (and pos (log-view-inside-comment-p pos)) (unless (and pos (log-view-inside-comment-p pos))
(error "Broken markup in `log-view-toggle-entry-display'")) (error "Broken markup in `log-view-toggle-entry-display'"))
(delete-region pos (delete-region pos
(next-single-property-change pos 'log-view-comment)) (or
(next-single-property-change pos 'log-view-comment)
(point-max)))
(put-text-property beg (1+ beg) 'log-view-entry-expanded nil) (put-text-property beg (1+ beg) 'log-view-entry-expanded nil)
(if (< opoint pos) (if (< opoint pos)
(goto-char opoint))) (goto-char opoint)))
@ -469,7 +471,10 @@ It assumes that a log entry starts with a line matching
((looking-back "Show 2X entries Show unlimited entries" ((looking-back "Show 2X entries Show unlimited entries"
(line-beginning-position)) (line-beginning-position))
(setq looping nil) (setq looping nil)
(forward-line -1)))))) (forward-line -1))
;; There are no buttons if we've turned on unlimited entries.
((eobp)
(setq looping nil))))))
(defun log-view-end-of-defun (&optional arg) (defun log-view-end-of-defun (&optional arg)
"Move forward to the next Log View entry. "Move forward to the next Log View entry.

View file

@ -582,17 +582,15 @@ the file in question, search for the log entry required and move point."
(setq prev-rev (setq prev-rev
(vc-call-backend vc-annotate-backend 'previous-revision (vc-call-backend vc-annotate-backend 'previous-revision
(if filediff fname nil) rev)) (if filediff fname nil) rev))
(if (not prev-rev) (vc-diff-internal
(message "Cannot diff from any revision prior to %s" rev) t
(vc-diff-internal ;; The value passed here should follow what
t ;; `vc-deduce-fileset' returns.
;; The value passed here should follow what (list vc-annotate-backend
;; `vc-deduce-fileset' returns. (if filediff
(list vc-annotate-backend (list fname)
(if filediff nil))
(list fname) prev-rev rev)))))
nil))
prev-rev rev))))))
(defun vc-annotate-show-diff-revision-at-line () (defun vc-annotate-show-diff-revision-at-line ()
"Visit the diff of the revision at line from its previous revision." "Visit the diff of the revision at line from its previous revision."

View file

@ -960,14 +960,13 @@ or BRANCH^ (where \"^\" can be repeated)."
(defun vc-git-expanded-log-entry (revision) (defun vc-git-expanded-log-entry (revision)
(with-temp-buffer (with-temp-buffer
(apply 'vc-git-command t nil nil (list "log" revision "-1")) (apply 'vc-git-command t nil nil (list "log" revision "-1" "--"))
(goto-char (point-min)) (goto-char (point-min))
(unless (eobp) (unless (eobp)
;; Indent the expanded log entry. ;; Indent the expanded log entry.
(indent-region (point-min) (point-max) 2) (indent-region (point-min) (point-max) 2)
(buffer-string)))) (buffer-string))))
(defun vc-git-region-history (file buffer lfrom lto) (defun vc-git-region-history (file buffer lfrom lto)
(vc-git-command buffer 'async nil "log" "-p" ;"--follow" ;FIXME: not supported? (vc-git-command buffer 'async nil "log" "-p" ;"--follow" ;FIXME: not supported?
(format "-L%d,%d:%s" lfrom lto (file-relative-name file)))) (format "-L%d,%d:%s" lfrom lto (file-relative-name file))))
@ -1019,12 +1018,18 @@ or BRANCH^ (where \"^\" can be repeated)."
(defun vc-git-diff (files &optional rev1 rev2 buffer async) (defun vc-git-diff (files &optional rev1 rev2 buffer async)
"Get a difference report using Git between two revisions of FILES." "Get a difference report using Git between two revisions of FILES."
(let (process-file-side-effects) (let (process-file-side-effects
(command "diff-tree"))
(if rev2
;; Diffing against the empty tree.
(unless rev1 (setq rev1 "4b825dc642cb6eb9a060e54bf8d69288fbee4904"))
(setq command "diff-index")
(unless rev1 (setq rev1 "HEAD")))
(if vc-git-diff-switches (if vc-git-diff-switches
(apply #'vc-git-command (or buffer "*vc-diff*") (apply #'vc-git-command (or buffer "*vc-diff*")
(if async 'async 1) (if async 'async 1)
files files
(if (and rev1 rev2) "diff-tree" "diff-index") command
"--exit-code" "--exit-code"
(append (vc-switches 'git 'diff) (append (vc-switches 'git 'diff)
(list "-p" (or rev1 "HEAD") rev2 "--"))) (list "-p" (or rev1 "HEAD") rev2 "--")))
@ -1033,7 +1038,7 @@ or BRANCH^ (where \"^\" can be repeated)."
(concat "diff " (concat "diff "
(mapconcat 'identity (mapconcat 'identity
(vc-switches nil 'diff) " ")) (vc-switches nil 'diff) " "))
(or rev1 "HEAD") rev2 "--")))) rev1 rev2 "--"))))
(defun vc-git-revision-table (_files) (defun vc-git-revision-table (_files)
;; What about `files'?!? --Stef ;; What about `files'?!? --Stef
@ -1061,7 +1066,7 @@ or BRANCH^ (where \"^\" can be repeated)."
(declare-function vc-annotate-convert-time "vc-annotate" (&optional time)) (declare-function vc-annotate-convert-time "vc-annotate" (&optional time))
(defun vc-git-annotate-time () (defun vc-git-annotate-time ()
(and (re-search-forward "^[0-9a-f]+[^()]+(.*?\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\) \\(:?\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([-+0-9]+\\)\\)? *[0-9]+) " nil t) (and (re-search-forward "^[0-9a-f^]+[^()]+(.*?\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\) \\(:?\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) \\([-+0-9]+\\)\\)? *[0-9]+) " nil t)
(vc-annotate-convert-time (vc-annotate-convert-time
(apply #'encode-time (mapcar (lambda (match) (apply #'encode-time (mapcar (lambda (match)
(if (match-beginning match) (if (match-beginning match)
@ -1072,7 +1077,7 @@ or BRANCH^ (where \"^\" can be repeated)."
(defun vc-git-annotate-extract-revision-at-line () (defun vc-git-annotate-extract-revision-at-line ()
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(when (looking-at "\\([0-9a-f^][0-9a-f]+\\) \\(\\([^(]+\\) \\)?") (when (looking-at "\\^?\\([0-9a-f]+\\) \\(\\([^(]+\\) \\)?")
(let ((revision (match-string-no-properties 1))) (let ((revision (match-string-no-properties 1)))
(if (match-beginning 2) (if (match-beginning 2)
(let ((fname (match-string-no-properties 3))) (let ((fname (match-string-no-properties 3)))

View file

@ -367,7 +367,8 @@
;; BUFFER is nil. If ASYNC is non-nil, run asynchronously. If REV1 ;; BUFFER is nil. If ASYNC is non-nil, run asynchronously. If REV1
;; and REV2 are non-nil, report differences from REV1 to REV2. If ;; and REV2 are non-nil, report differences from REV1 to REV2. If
;; REV1 is nil, use the working revision (as found in the ;; REV1 is nil, use the working revision (as found in the
;; repository) as the older revision; if REV2 is nil, use the ;; repository) as the older revision if REV2 is nil as well;
;; otherwise, diff against an empty tree. If REV2 is nil, use the
;; current working-copy contents as the newer revision. This ;; current working-copy contents as the newer revision. This
;; function should pass the value of (vc-switches BACKEND 'diff) to ;; function should pass the value of (vc-switches BACKEND 'diff) to
;; the backend command. It should return a status of either 0 (no ;; the backend command. It should return a status of either 0 (no