unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
@ 2012-02-03 16:30 Wolfgang Schnerring
  2012-02-03 17:04 ` Glenn Morris
  2012-12-01  1:12 ` Glenn Morris
  0 siblings, 2 replies; 11+ messages in thread
From: Wolfgang Schnerring @ 2012-02-03 16:30 UTC (permalink / raw)
  To: 10709

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

Hello,

vc-svn has the useful behaviour (via vc-svn-find-file-hook) that when
you visit a file with conflicts, it drops you into smerge-mode, and
automatically marks the file as resolved once you've removed all
conflict markers. This makes for a very seamless editing experience. :-)

It would be nice if vc-hg did the same. I guess most of the behaviour
can be lifted straight from vc-svn, however I didn't find anything to
suggest that vc-hg talks to "hg resolve -l" at the moment, which is
needed to find out whether the current file is conflicted. So I guess
that would be the starting point.

My elisp is rather weak, so I probably won't be of much help here, but
do let me know if there's something I can do.

Wolfgang

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 16:30 bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts Wolfgang Schnerring
@ 2012-02-03 17:04 ` Glenn Morris
  2012-02-03 17:11   ` Glenn Morris
  2012-02-03 18:43   ` Stefan Monnier
  2012-12-01  1:12 ` Glenn Morris
  1 sibling, 2 replies; 11+ messages in thread
From: Glenn Morris @ 2012-02-03 17:04 UTC (permalink / raw)
  To: Wolfgang Schnerring; +Cc: 10709

Wolfgang Schnerring wrote:

> vc-svn has the useful behaviour (via vc-svn-find-file-hook) that when
> you visit a file with conflicts, it drops you into smerge-mode, and
> automatically marks the file as resolved once you've removed all
> conflict markers. This makes for a very seamless editing experience. :-)
>
> It would be nice if vc-hg did the same.

I guess you need to get hg to generate standard conflict markers. Ref:

https://lists.ubuntu.com/archives/bazaar/2012q1/074313.html





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 17:04 ` Glenn Morris
@ 2012-02-03 17:11   ` Glenn Morris
  2012-02-03 18:27     ` Wolfgang Schnerring
  2012-02-03 18:43   ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Glenn Morris @ 2012-02-03 17:11 UTC (permalink / raw)
  To: Wolfgang Schnerring; +Cc: 10709

Glenn Morris wrote:

> I guess you need to get hg to generate standard conflict markers. Ref:

Actually I guess vc-hg would need some changes too.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 17:11   ` Glenn Morris
@ 2012-02-03 18:27     ` Wolfgang Schnerring
  2012-02-03 19:32       ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfgang Schnerring @ 2012-02-03 18:27 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10709

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]

* Glenn Morris <rgm@gnu.org> [2012-02-03 12:11]:
> Glenn Morris wrote:
> > I guess you need to get hg to generate standard conflict markers. Ref:

You could configure diff3 as the default merge program.
However, in my experience, using smerge-mode on the "internal:merge"
results of hg worked, too.
 
> Actually I guess vc-hg would need some changes too.

Yep, I guess you'd need changes on both ends.

Wolfgang

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 17:04 ` Glenn Morris
  2012-02-03 17:11   ` Glenn Morris
@ 2012-02-03 18:43   ` Stefan Monnier
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2012-02-03 18:43 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10709, Wolfgang Schnerring

>> vc-svn has the useful behaviour (via vc-svn-find-file-hook) that when
>> you visit a file with conflicts, it drops you into smerge-mode, and
>> automatically marks the file as resolved once you've removed all
>> conflict markers. This makes for a very seamless editing experience. :-)
>> It would be nice if vc-hg did the same.
> I guess you need to get hg to generate standard conflict markers. Ref:
> https://lists.ubuntu.com/archives/bazaar/2012q1/074313.html

Note: I do not know that hg uses non-standard conflict markers.


        Stefan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 18:27     ` Wolfgang Schnerring
@ 2012-02-03 19:32       ` Stefan Monnier
  2012-02-04  9:46         ` Wolfgang Schnerring
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2012-02-03 19:32 UTC (permalink / raw)
  To: Wolfgang Schnerring; +Cc: 10709

>> > I guess you need to get hg to generate standard conflict markers. Ref:
> You could configure diff3 as the default merge program.
> However, in my experience, using smerge-mode on the "internal:merge"
> results of hg worked, too.

So you're saying that hg uses standard conflict markers in its
internal:merge code?  Wonderful.

>> Actually I guess vc-hg would need some changes too.
> Yep, I guess you'd need changes on both ends.

Apparently only vc-hg.el needs to be changed, then.


        Stefan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 19:32       ` Stefan Monnier
@ 2012-02-04  9:46         ` Wolfgang Schnerring
  2012-02-06 13:27           ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfgang Schnerring @ 2012-02-04  9:46 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10709

[-- Attachment #1: Type: text/plain, Size: 828 bytes --]

* Stefan Monnier <monnier@iro.umontreal.ca> [2012-02-03 14:32]:
> So you're saying that hg uses standard conflict markers in its
> internal:merge code?  Wonderful.

I've just double-checked: yes, it does. Here's an example of a file
with conflicts:

<<<<<<< local
foo = baz
=======
foo = qux
>>>>>>> other

This matches the markers defined in smerge-mode, and invoking
smerge-mode manually on the example file works just fine, just as I
remembered.

> >> Actually I guess vc-hg would need some changes too.
> > Yep, I guess you'd need changes on both ends.
> 
> Apparently only vc-hg.el needs to be changed, then.

Yup, this brings me back to my original chain of thought: vc-hg needs
to learn to detect conflicted files, and the vc-find-file-hook needs
to be ported/abstracted from vc-svn.

Wolfgang

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-04  9:46         ` Wolfgang Schnerring
@ 2012-02-06 13:27           ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2012-02-06 13:27 UTC (permalink / raw)
  To: Wolfgang Schnerring; +Cc: 10709

>> So you're saying that hg uses standard conflict markers in its
>> internal:merge code?  Wonderful.
> I've just double-checked: yes, it does. Here's an example of a file
> with conflicts:

> <<<<<<< local
> foo = baz
> =======
> foo = qux
>>>>>>>> other

> This matches the markers defined in smerge-mode, and invoking
> smerge-mode manually on the example file works just fine, just as I
> remembered.

>> >> Actually I guess vc-hg would need some changes too.
>> > Yep, I guess you'd need changes on both ends.
>> 
>> Apparently only vc-hg.el needs to be changed, then.

> Yup, this brings me back to my original chain of thought: vc-hg needs
> to learn to detect conflicted files, and the vc-find-file-hook needs
> to be ported/abstracted from vc-svn.

You can also check vc-bzr.el which has similar code.


        Stefan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-02-03 16:30 bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts Wolfgang Schnerring
  2012-02-03 17:04 ` Glenn Morris
@ 2012-12-01  1:12 ` Glenn Morris
  2012-12-01  4:42   ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Glenn Morris @ 2012-12-01  1:12 UTC (permalink / raw)
  To: Wolfgang Schnerring; +Cc: 10709

Wolfgang Schnerring wrote:

> vc-svn has the useful behaviour (via vc-svn-find-file-hook) that when
> you visit a file with conflicts, it drops you into smerge-mode, and
> automatically marks the file as resolved once you've removed all
> conflict markers. This makes for a very seamless editing experience. :-)
>
> It would be nice if vc-hg did the same. I guess most of the behaviour
> can be lifted straight from vc-svn, however I didn't find anything to
> suggest that vc-hg talks to "hg resolve -l" at the moment, which is
> needed to find out whether the current file is conflicted. So I guess
> that would be the starting point.

Maybe something like this, copied from vc-bzr?

The detection of a conflict is poor and Needs Work. With bzr we have
.BASE, .OTHER, and .THIS files present. With hg, conflicts don't even
seem to show up in "hg status". It's probably not a good idea to call
"hg resolve -l" on every single visit to an hg controlled file.
Nor is it probably a good idea to search the entirety of every file for
<<<< markers without some other clue suggesting a conflict. I used .orig
files because I seemed to get one in my two minutes playing with hg.
These don't seem to get cleaned up on hg resolve, so maybe
vc-hg-resolve-when-done should do that too? However, .orig is a very
vague, general file name.

*** lisp/vc/vc-hg.el	2012-07-19 14:38:01 +0000
--- lisp/vc/vc-hg.el	2012-12-01 01:01:18 +0000
***************
*** 464,469 ****
--- 464,492 ----
          (vc-hg-command t 0 file "cat" "-r" rev)
        (vc-hg-command t 0 file "cat")))))
  
+ (defun vc-hg-resolve-when-done ()
+   "Call \"hg resolve -m\" if the conflict markers have been removed."
+   (save-excursion
+     (goto-char (point-min))
+     (unless (re-search-forward "^<<<<<<< " nil t)
+       (vc-hg-command nil 0 buffer-file-name "resolve" "-m")
+       ;; Remove the hook so that it is not called multiple times.
+       (remove-hook 'after-save-hook 'vc-hg-resolve-when-done t))))
+ 
+ (defun vc-hg-find-file-hook ()
+   (when (and buffer-file-name
+              (file-exists-p (concat buffer-file-name ".orig"))
+              ;; FIXME: We should check that "hg resolve -l" says "U".
+              ;; If "hg resolve -l" says there's a conflict but there are no
+              ;; conflict markers, it's not clear what we should do.
+              (save-excursion
+                (goto-char (point-min))
+                (re-search-forward "^<<<<<<< " nil t)))
+     (smerge-start-session)
+     (add-hook 'after-save-hook 'vc-hg-resolve-when-done nil t)
+     (message "There are unresolved conflicts in this file")))
+ 
+ 
  ;; Modeled after the similar function in vc-bzr.el
  (defun vc-hg-workfile-unchanged-p (file)
    (eq 'up-to-date (vc-hg-state file)))





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-12-01  1:12 ` Glenn Morris
@ 2012-12-01  4:42   ` Stefan Monnier
  2012-12-05  1:53     ` Glenn Morris
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2012-12-01  4:42 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10709, Wolfgang Schnerring

> The detection of a conflict is poor and Needs Work. With bzr we have

Maybe we should ask on a Mercurial list how it can be done (and turn it
into a feature request if there's no good answer)?


        Stefan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
  2012-12-01  4:42   ` Stefan Monnier
@ 2012-12-05  1:53     ` Glenn Morris
  0 siblings, 0 replies; 11+ messages in thread
From: Glenn Morris @ 2012-12-05  1:53 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10709, Wolfgang Schnerring

Stefan Monnier wrote:

>> The detection of a conflict is poor and Needs Work. With bzr we have
>
> Maybe we should ask on a Mercurial list how it can be done (and turn it
> into a feature request if there's no good answer)?

AFAICS they have set their face against it, eg

http://bz.selenic.com/show_bug.cgi?id=2724  # RESOLVED FIXED

I think checking for state = 'edited, plus .orig file, plus conflict
markers is good enough for a start, so I installed that to trunk and we
can see how it works out for people.

BTW, I think this stuff should be abstracted to a general
vc-find-file-hook/after-save-hook that calls vc-BACKEND-conflicted-p.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-12-05  1:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-03 16:30 bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts Wolfgang Schnerring
2012-02-03 17:04 ` Glenn Morris
2012-02-03 17:11   ` Glenn Morris
2012-02-03 18:27     ` Wolfgang Schnerring
2012-02-03 19:32       ` Stefan Monnier
2012-02-04  9:46         ` Wolfgang Schnerring
2012-02-06 13:27           ` Stefan Monnier
2012-02-03 18:43   ` Stefan Monnier
2012-12-01  1:12 ` Glenn Morris
2012-12-01  4:42   ` Stefan Monnier
2012-12-05  1:53     ` Glenn Morris

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).