* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
@ 2016-10-18 14:27 Tino Calancha
2016-10-19 23:22 ` Dmitry Gutov
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-10-18 14:27 UTC (permalink / raw)
To: 24725
emacs -Q lisp/vc/vc.el
C-x h
M-x vc-region-history RET
fatal: file vc.el has only 2921 lines
;; vc.el has 2922 lines but Git ignores the last empty line.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 12a6fc588fe60ebf98443a0fd068fe77d63bd17e Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Tue, 18 Oct 2016 23:20:07 +0900
Subject: [PATCH] vc-region-history: Do not exceed the file maximum line number
The last empty line in a file is not part of the Git repository.
* lisp/vc/vc.el (vc-region-history): Exclude the last empty line
from the region (Bug#24724).
---
lisp/vc/vc-git.el | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 9eac5b2..762f6af 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1016,6 +1016,8 @@ vc-git-region-history
;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but
;; since Git is the only backend to support this operation so far, it's hard
;; to tell.
+ (when (> lto (1- (line-number-at-pos (point-max))))
+ (setq lto (1- (line-number-at-pos (point-max)))))
(with-temp-buffer
(vc-call-backend 'git 'diff file "HEAD" nil (current-buffer))
(goto-char (point-min))
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.1)
of 2016-10-13 built on calancha-pc
Repository revision: baa8ba4ed471d7fe4bb07c80a9dd16c4712525b4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-18 14:27 bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository Tino Calancha
@ 2016-10-19 23:22 ` Dmitry Gutov
2016-10-20 4:22 ` Tino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Gutov @ 2016-10-19 23:22 UTC (permalink / raw)
To: Tino Calancha, 24725
Hi!
On 18.10.2016 17:27, Tino Calancha wrote:
>
> emacs -Q lisp/vc/vc.el
> C-x h
> M-x vc-region-history RET
> fatal: file vc.el has only 2921 lines
> ;; vc.el has 2922 lines but Git ignores the last empty line.
With your patch, what will happen if the file does not end with a
newline (which can be some people's or tools' preference)?
Currently, in that case the above scenario works fine. Maybe we need a
different check, rather than substracting.
Or try (line-number-at-pos (1- (point-max))) instead of (1-
(line-number-at-pos (point-max))).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-19 23:22 ` Dmitry Gutov
@ 2016-10-20 4:22 ` Tino Calancha
2016-10-20 7:27 ` Andreas Schwab
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-10-20 4:22 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: 24725, tino.calancha
Dmitry Gutov <dgutov@yandex.ru> writes:
> Hi!
>
> On 18.10.2016 17:27, Tino Calancha wrote:
>>
>> emacs -Q lisp/vc/vc.el
>> C-x h
>> M-x vc-region-history RET
>> fatal: file vc.el has only 2921 lines
>> ;; vc.el has 2922 lines but Git ignores the last empty line.
>
> With your patch, what will happen if the file does not end with a
> newline (which can be some people's or tools' preference)?
In that case my patch is wrong: it excludes the last line from the region.
> Currently, in that case the above scenario works fine. Maybe we need a
> different check, rather than substracting.
>
> Or try (line-number-at-pos (1- (point-max))) instead of (1-
> (line-number-at-pos (point-max))).
Thank you. Your suggestion handle both cases correctly.
Following is the new patch:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From c9ce3a54f572549ea2027108694eb556b5cbe8f3 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Thu, 20 Oct 2016 12:22:51 +0900
Subject: [PATCH] vc-region-history: Do not exceed the file maximum line number
The last empty line in a file is not part of the Git repository.
* lisp/vc/vc.el (vc-region-history): Exclude the last empty line
from the region (Bug#24725).
---
lisp/vc/vc-git.el | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 9eac5b2..c6a9064 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1016,6 +1016,8 @@ vc-git-region-history
;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but
;; since Git is the only backend to support this operation so far, it's hard
;; to tell.
+ (when (> lto (line-number-at-pos (1- (point-max))))
+ (setq lto (line-number-at-pos (1- (point-max)))))
(with-temp-buffer
(vc-call-backend 'git 'diff file "HEAD" nil (current-buffer))
(goto-char (point-min))
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.1)
of 2016-10-20
Repository revision: 8988327d548db7b69f30ea15496ccb0726fa4502
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-20 4:22 ` Tino Calancha
@ 2016-10-20 7:27 ` Andreas Schwab
2016-10-20 8:09 ` Tino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2016-10-20 7:27 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24725, Dmitry Gutov
On Okt 20 2016, Tino Calancha <tino.calancha@gmail.com> wrote:
> diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
> index 9eac5b2..c6a9064 100644
> --- a/lisp/vc/vc-git.el
> +++ b/lisp/vc/vc-git.el
> @@ -1016,6 +1016,8 @@ vc-git-region-history
> ;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but
> ;; since Git is the only backend to support this operation so far, it's hard
> ;; to tell.
> + (when (> lto (line-number-at-pos (1- (point-max))))
> + (setq lto (line-number-at-pos (1- (point-max)))))
Shouldn't that be fixed in the caller, and lto always be decremented if
the regions ends at bol?
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-20 7:27 ` Andreas Schwab
@ 2016-10-20 8:09 ` Tino Calancha
2016-10-20 10:21 ` Dmitry Gutov
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-10-20 8:09 UTC (permalink / raw)
To: Andreas Schwab; +Cc: 24725, Dmitry Gutov, Tino Calancha
Andreas Schwab <schwab@suse.de> writes:
> On Okt 20 2016, Tino Calancha <tino.calancha@gmail.com> wrote:
>
>> diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
>> index 9eac5b2..c6a9064 100644
>> --- a/lisp/vc/vc-git.el
>> +++ b/lisp/vc/vc-git.el
>> @@ -1016,6 +1016,8 @@ vc-git-region-history
>> ;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but
>> ;; since Git is the only backend to support this operation so far, it's hard
>> ;; to tell.
>> + (when (> lto (line-number-at-pos (1- (point-max))))
>> + (setq lto (line-number-at-pos (1- (point-max)))))
>
> Shouldn't that be fixed in the caller, and lto always be decremented if
> the regions ends at bol?
I think you are right. Otherwise we are including a line out of the
region, i.e., in interactive calls we also search in the history for
a line out of the highlighted region.
How about following new patch?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From b05b6d12171ea270f6b392c8af7f4415414960e5 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Thu, 20 Oct 2016 17:00:04 +0900
Subject: [PATCH] vc-region-history: Search just on lines within the region
* lisp/vc/vc.el (vc-region-history): If region ends in the beginning
of a line, then exclude that line from the search (Bug#24725).
---
lisp/vc/vc.el | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index af875e8..0d8e308 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2393,7 +2393,11 @@ vc-region-history
"Show the history of the region FROM..TO."
(interactive "r")
(let* ((lfrom (line-number-at-pos from))
- (lto (line-number-at-pos to))
+ (lto (save-excursion
+ (goto-char to)
+ (if (bolp)
+ (1- (line-number-at-pos to))
+ (line-number-at-pos to))))
(file buffer-file-name)
(backend (vc-backend file))
(buf (get-buffer-create "*VC-history*")))
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.1)
of 2016-10-20
Repository revision: 8988327d548db7b69f30ea15496ccb0726fa4502
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-20 8:09 ` Tino Calancha
@ 2016-10-20 10:21 ` Dmitry Gutov
2016-10-20 10:44 ` Tino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Gutov @ 2016-10-20 10:21 UTC (permalink / raw)
To: Tino Calancha, Andreas Schwab; +Cc: 24725
On 20.10.2016 11:09, Tino Calancha wrote:
>> Shouldn't that be fixed in the caller, and lto always be decremented if
>> the regions ends at bol?
> I think you are right. Otherwise we are including a line out of the
> region, i.e., in interactive calls we also search in the history for
> a line out of the highlighted region.
> How about following new patch?
LGTM, please install.
Although I was thinking of simplifying it to just:
(line-number-at-pos (1- to))
That can only bite us if TO is at bob, which would be very unusual.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository
2016-10-20 10:21 ` Dmitry Gutov
@ 2016-10-20 10:44 ` Tino Calancha
0 siblings, 0 replies; 7+ messages in thread
From: Tino Calancha @ 2016-10-20 10:44 UTC (permalink / raw)
To: 24725-done; +Cc: Dmitry Gutov
Dmitry Gutov <dgutov@yandex.ru> writes:
> On 20.10.2016 11:09, Tino Calancha wrote:
>
>>> Shouldn't that be fixed in the caller, and lto always be decremented if
>>> the regions ends at bol?
>> I think you are right. Otherwise we are including a line out of the
>> region, i.e., in interactive calls we also search in the history for
>> a line out of the highlighted region.
>> How about following new patch?
>
> LGTM, please install.
>
> Although I was thinking of simplifying it to just:
>
> (line-number-at-pos (1- to))
>
> That can only bite us if TO is at bob, which would be very unusual.
Good. It sounds more simple.
Pushed that simple fix to emacs-25 branch as commit 3877c911
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-20 10:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18 14:27 bug#24725: 25.1.50; vc-region-history may exceed max line number of file in repository Tino Calancha
2016-10-19 23:22 ` Dmitry Gutov
2016-10-20 4:22 ` Tino Calancha
2016-10-20 7:27 ` Andreas Schwab
2016-10-20 8:09 ` Tino Calancha
2016-10-20 10:21 ` Dmitry Gutov
2016-10-20 10:44 ` Tino Calancha
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).