diff options
| author | Stefan Monnier | 2015-10-02 15:24:23 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-10-02 15:24:23 -0400 |
| commit | a5c20339c5318a59b0cafd7df6bf476e957d05d4 (patch) | |
| tree | bab83517dcf5a2e53d75c5b710fe019f217e527f /lisp | |
| parent | 355ccbcf332d766231bd441e0971e481907785bc (diff) | |
| download | emacs-a5c20339c5318a59b0cafd7df6bf476e957d05d4.tar.gz emacs-a5c20339c5318a59b0cafd7df6bf476e957d05d4.zip | |
* lisp/vc/vc-git.el (vc-git-region-history): Handle local changes
Adjust lto/lfrom when we have uncommitted changes.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/vc/vc-git.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 2f0439365e8..b5570323e03 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el | |||
| @@ -974,6 +974,34 @@ or BRANCH^ (where \"^\" can be repeated)." | |||
| 974 | (buffer-string)))) | 974 | (buffer-string)))) |
| 975 | 975 | ||
| 976 | (defun vc-git-region-history (file buffer lfrom lto) | 976 | (defun vc-git-region-history (file buffer lfrom lto) |
| 977 | ;; The "git log" command below interprets the line numbers as applying | ||
| 978 | ;; to the HEAD version of the file, not to the current state of the file. | ||
| 979 | ;; So we need to look at all the local changes and adjust lfrom/lto | ||
| 980 | ;; accordingly. | ||
| 981 | ;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but | ||
| 982 | ;; since Git is the only backend to support this operation so far, it's hard | ||
| 983 | ;; to tell. | ||
| 984 | (with-temp-buffer | ||
| 985 | (vc-call-backend 'git 'diff file "HEAD" nil (current-buffer)) | ||
| 986 | (goto-char (point-min)) | ||
| 987 | (let ((last-offset 0) | ||
| 988 | (from-offset nil) | ||
| 989 | (to-offset nil)) | ||
| 990 | (while (re-search-forward | ||
| 991 | "^@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@" nil t) | ||
| 992 | (let ((headno (string-to-number (match-string 1))) | ||
| 993 | (headcnt (string-to-number (match-string 2))) | ||
| 994 | (curno (string-to-number (match-string 3))) | ||
| 995 | (curcnt (string-to-number (match-string 4)))) | ||
| 996 | (cl-assert (equal (- curno headno) last-offset)) | ||
| 997 | (and (null from-offset) (> curno lfrom) | ||
| 998 | (setq from-offset last-offset)) | ||
| 999 | (and (null to-offset) (> curno lto) | ||
| 1000 | (setq to-offset last-offset)) | ||
| 1001 | (setq last-offset | ||
| 1002 | (- (+ curno curcnt) (+ headno headcnt))))) | ||
| 1003 | (setq lto (- lto (or to-offset last-offset))) | ||
| 1004 | (setq lfrom (- lfrom (or to-offset last-offset))))) | ||
| 977 | (vc-git-command buffer 'async nil "log" "-p" ;"--follow" ;FIXME: not supported? | 1005 | (vc-git-command buffer 'async nil "log" "-p" ;"--follow" ;FIXME: not supported? |
| 978 | (format "-L%d,%d:%s" lfrom lto (file-relative-name file)))) | 1006 | (format "-L%d,%d:%s" lfrom lto (file-relative-name file)))) |
| 979 | 1007 | ||