Quantcast

[PATCH 1 of 2 contrib] contrib: add editmerge version for powershell

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 1 of 2 contrib] contrib: add editmerge version for powershell

Kostia Balytskyi-2
# HG changeset patch
# User Kostia Balytskyi <[hidden email]>
# Date 1495143406 25200
#      Thu May 18 14:36:46 2017 -0700
# Node ID 2412345e35cc0b17c98e050a480cb4b4f03bd5bb
# Parent  5b363e91f853c9c0f982ba02dedddd320dac0215
contrib: add editmerge version for powershell

This just adds a translation of existing contrib/editmerge to powershell.
It allows users on Windows to iteratively resolve conflicts in their
editor of choice.

diff --git a/contrib/editmergeps.bat b/contrib/editmergeps.bat
new file mode 100644
--- /dev/null
+++ b/contrib/editmergeps.bat
@@ -0,0 +1,2 @@
+@echo off
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "& 'editmergeps.ps1' %*"
diff --git a/contrib/editmergeps.ps1 b/contrib/editmergeps.ps1
new file mode 100644
--- /dev/null
+++ b/contrib/editmergeps.ps1
@@ -0,0 +1,69 @@
+# A simple script for opening merge conflicts in editor
+# A loose translation of contrib/editmerge to powershell
+# Please make sure that both editmergeps.bat and editmerge.ps1 are available
+# via %PATH% and use the following Mercurial settings to enable it
+#
+# [ui]
+# editmergeps
+# editmergeps.args=$output
+# editmergeps.check=changed
+# editmergeps.premerge=keep
+
+$file=$args[0]
+
+function Get-Lines
+{
+  Select-String "^<<<<<<" $file | % {"$($_.LineNumber)"}
+}
+
+$ed = $Env:HGEDITOR;
+if ($ed -eq $nil)
+{
+  $ed = $Env:VISUAL;
+}
+if ($ed -eq $nil)
+{
+  $ed = $Env:EDITOR;
+}
+if ($ed -eq $nil)
+{
+  $ed = $(hg showconfig ui.editor);
+}
+if ($ed -eq $nil)
+{
+  Write-Error "merge failed - unable to find editor"
+  exit 1
+}
+
+if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano"))
+{
+  $lines = Get-Lines
+  $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
+  $previousline = $nil;
+
+
+  # open the editor to the first conflict until there are no more
+  # or the user stops editing the file
+  while (($firstline -ne $nil) -and ($firstline -ne $previousline))
+  {
+    & "$ed" "+$firstline" "$file"
+    $previousline = $firstline
+    $lines = Get-Lines
+    $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
+    Write-Output "firstline is: $firstline, previousline is: $previousline"
+  }
+}
+else
+{
+  $ "$ed" $file
+}
+
+$conflicts=Get-Lines
+if ($conflicts.Length -ne 0)
+{
+  Write-Output "merge failed - resolve the conflicts (line $conflicts) then use 'hg resolve --mark'"
+  exit 1
+}
+
+exit 0
+
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 2 of 2 contrib] contrib: make editmergeps able to work with notepad++

Kostia Balytskyi-2
# HG changeset patch
# User Kostia Balytskyi <[hidden email]>
# Date 1495148281 25200
#      Thu May 18 15:58:01 2017 -0700
# Node ID f715f6839ba2b93193334145e677d13a0f99cf89
# Parent  2412345e35cc0b17c98e050a480cb4b4f03bd5bb
contrib: make editmergeps able to work with notepad++

This patch teaches editmergeps to work with Notepad++ editor. Tricky part
is to use Start-Process -Wait to make hg to wait for editor UI to close.

diff --git a/contrib/editmergeps.ps1 b/contrib/editmergeps.ps1
--- a/contrib/editmergeps.ps1
+++ b/contrib/editmergeps.ps1
@@ -35,7 +35,8 @@ if ($ed -eq $nil)
   exit 1
 }
 
-if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano"))
+if (($ed -eq "vim") -or ($ed -eq "emacs") -or `
+    ($ed -eq "nano") -or ($ed -eq "notepad++"))
 {
   $lines = Get-Lines
   $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
@@ -46,7 +47,16 @@ if (($ed -eq "vim") -or ($ed -eq "emacs"
   # or the user stops editing the file
   while (($firstline -ne $nil) -and ($firstline -ne $previousline))
   {
-    & "$ed" "+$firstline" "$file"
+    if ($ed -eq "notepad++")
+    {
+        $linearg = "-n$firstline"
+    }
+    else
+    {
+        $linearg = "+$firstline"
+    }
+
+    Start-Process -Wait $ed $linearg,$file
     $previousline = $firstline
     $lines = Get-Lines
     $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 2 of 2 contrib] contrib: make editmergeps able to work with notepad++

Augie Fackler-2
On Thu, May 18, 2017 at 04:06:08PM -0700, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <[hidden email]>
> # Date 1495148281 25200
> #      Thu May 18 15:58:01 2017 -0700
> # Node ID f715f6839ba2b93193334145e677d13a0f99cf89
> # Parent  2412345e35cc0b17c98e050a480cb4b4f03bd5bb
> contrib: make editmergeps able to work with notepad++

Huh. Don't you need the -Wait for any $EDITOR? (Forgive me, I don't
know a darn thing about powershell.)

I've taken patch 1 since it seems totally reasonable.

>
> This patch teaches editmergeps to work with Notepad++ editor. Tricky part
> is to use Start-Process -Wait to make hg to wait for editor UI to close.
>
> diff --git a/contrib/editmergeps.ps1 b/contrib/editmergeps.ps1
> --- a/contrib/editmergeps.ps1
> +++ b/contrib/editmergeps.ps1
> @@ -35,7 +35,8 @@ if ($ed -eq $nil)
>    exit 1
>  }
>
> -if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano"))
> +if (($ed -eq "vim") -or ($ed -eq "emacs") -or `
> +    ($ed -eq "nano") -or ($ed -eq "notepad++"))
>  {
>    $lines = Get-Lines
>    $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
> @@ -46,7 +47,16 @@ if (($ed -eq "vim") -or ($ed -eq "emacs"
>    # or the user stops editing the file
>    while (($firstline -ne $nil) -and ($firstline -ne $previousline))
>    {
> -    & "$ed" "+$firstline" "$file"
> +    if ($ed -eq "notepad++")
> +    {
> +        $linearg = "-n$firstline"
> +    }
> +    else
> +    {
> +        $linearg = "+$firstline"
> +    }
> +
> +    Start-Process -Wait $ed $linearg,$file
>      $previousline = $firstline
>      $lines = Get-Lines
>      $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
> _______________________________________________
> Mercurial-devel mailing list
> [hidden email]
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: [PATCH 2 of 2 contrib] contrib: make editmergeps able to work with notepad++

Kostia Balytskyi-2


> -----Original Message-----
> From: Augie Fackler [mailto:[hidden email]]
> Sent: Friday, 19 May, 2017 14:43
> To: Kostia Balytskyi <[hidden email]>
> Cc: [hidden email]
> Subject: Re: [PATCH 2 of 2 contrib] contrib: make editmergeps able to work
> with notepad++
>
> On Thu, May 18, 2017 at 04:06:08PM -0700, Kostia Balytskyi wrote:
> > # HG changeset patch
> > # User Kostia Balytskyi <[hidden email]> # Date 1495148281 25200
> > #      Thu May 18 15:58:01 2017 -0700
> > # Node ID f715f6839ba2b93193334145e677d13a0f99cf89
> > # Parent  2412345e35cc0b17c98e050a480cb4b4f03bd5bb
> > contrib: make editmergeps able to work with notepad++
>
> Huh. Don't you need the -Wait for any $EDITOR? (Forgive me, I don't know a
> darn thing about powershell.)
Me neither :P
But this patch makes it so every editor will be invoked with -Wait.  It seems not needed for non-Windows-UI apps (like cmd vim), but it also does not seem to hurt.

>
> I've taken patch 1 since it seems totally reasonable.
>
> >
> > This patch teaches editmergeps to work with Notepad++ editor. Tricky
> > part is to use Start-Process -Wait to make hg to wait for editor UI to close.
> >
> > diff --git a/contrib/editmergeps.ps1 b/contrib/editmergeps.ps1
> > --- a/contrib/editmergeps.ps1
> > +++ b/contrib/editmergeps.ps1
> > @@ -35,7 +35,8 @@ if ($ed -eq $nil)
> >    exit 1
> >  }
> >
> > -if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano"))
> > +if (($ed -eq "vim") -or ($ed -eq "emacs") -or `
> > +    ($ed -eq "nano") -or ($ed -eq "notepad++"))
> >  {
> >    $lines = Get-Lines
> >    $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
> > @@ -46,7 +47,16 @@ if (($ed -eq "vim") -or ($ed -eq "emacs"
> >    # or the user stops editing the file
> >    while (($firstline -ne $nil) -and ($firstline -ne $previousline))
> >    {
> > -    & "$ed" "+$firstline" "$file"
> > +    if ($ed -eq "notepad++")
> > +    {
> > +        $linearg = "-n$firstline"
> > +    }
> > +    else
> > +    {
> > +        $linearg = "+$firstline"
> > +    }
> > +
> > +    Start-Process -Wait $ed $linearg,$file
> >      $previousline = $firstline
> >      $lines = Get-Lines
> >      $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
> > _______________________________________________
> > Mercurial-devel mailing list
> > [hidden email]
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-
> 2Dscm.org_mailman_listinfo_mercurial-
> 2Ddevel&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-
> gQYFgs4tKlSFPF5kfCw&m=1ucFRbTnUDTCrF1Tgq0PGnPiICsGO-
> GS0om9POdCP7U&s=_qFYXF81hHuuc3goCvrtHMakJ191DgZrVEkFFcOK9oM&
> e=
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 2 of 2 contrib] contrib: make editmergeps able to work with notepad++

Augie Fackler-2

> On May 19, 2017, at 15:38, Kostia Balytskyi <[hidden email]> wrote:
>
>
>
>> -----Original Message-----
>> From: Augie Fackler [mailto:[hidden email]]
>> Sent: Friday, 19 May, 2017 14:43
>> To: Kostia Balytskyi <[hidden email]>
>> Cc: [hidden email]
>> Subject: Re: [PATCH 2 of 2 contrib] contrib: make editmergeps able to work
>> with notepad++
>>
>> On Thu, May 18, 2017 at 04:06:08PM -0700, Kostia Balytskyi wrote:
>>> # HG changeset patch
>>> # User Kostia Balytskyi <[hidden email]> # Date 1495148281 25200
>>> #      Thu May 18 15:58:01 2017 -0700
>>> # Node ID f715f6839ba2b93193334145e677d13a0f99cf89
>>> # Parent  2412345e35cc0b17c98e050a480cb4b4f03bd5bb
>>> contrib: make editmergeps able to work with notepad++
>>
>> Huh. Don't you need the -Wait for any $EDITOR? (Forgive me, I don't know a
>> darn thing about powershell.)
> Me neither :P
> But this patch makes it so every editor will be invoked with -Wait.

Ah. Could this be two patches then? one that does the -Wait and another that adds the support for notepad++'s linearg business?

I think that's what confused me.

>  It seems not needed for non-Windows-UI apps (like cmd vim), but it also does not seem to hurt.
>
>>
>> I've taken patch 1 since it seems totally reasonable.
>>
>>>
>>> This patch teaches editmergeps to work with Notepad++ editor. Tricky
>>> part is to use Start-Process -Wait to make hg to wait for editor UI to close.
>>>
>>> diff --git a/contrib/editmergeps.ps1 b/contrib/editmergeps.ps1
>>> --- a/contrib/editmergeps.ps1
>>> +++ b/contrib/editmergeps.ps1
>>> @@ -35,7 +35,8 @@ if ($ed -eq $nil)
>>>   exit 1
>>> }
>>>
>>> -if (($ed -eq "vim") -or ($ed -eq "emacs") -or ($ed -eq "nano"))
>>> +if (($ed -eq "vim") -or ($ed -eq "emacs") -or `
>>> +    ($ed -eq "nano") -or ($ed -eq "notepad++"))
>>> {
>>>   $lines = Get-Lines
>>>   $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
>>> @@ -46,7 +47,16 @@ if (($ed -eq "vim") -or ($ed -eq "emacs"
>>>   # or the user stops editing the file
>>>   while (($firstline -ne $nil) -and ($firstline -ne $previousline))
>>>   {
>>> -    & "$ed" "+$firstline" "$file"
>>> +    if ($ed -eq "notepad++")
>>> +    {
>>> +        $linearg = "-n$firstline"
>>> +    }
>>> +    else
>>> +    {
>>> +        $linearg = "+$firstline"
>>> +    }
>>> +
>>> +    Start-Process -Wait $ed $linearg,$file
>>>     $previousline = $firstline
>>>     $lines = Get-Lines
>>>     $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
>>> _______________________________________________
>>> Mercurial-devel mailing list
>>> [hidden email]
>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-
>> 2Dscm.org_mailman_listinfo_mercurial-
>> 2Ddevel&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-
>> gQYFgs4tKlSFPF5kfCw&m=1ucFRbTnUDTCrF1Tgq0PGnPiICsGO-
>> GS0om9POdCP7U&s=_qFYXF81hHuuc3goCvrtHMakJ191DgZrVEkFFcOK9oM&
>> e=

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Loading...