contrib/editmergeps.ps1
author C. Masloch <pushbx@ulukai.org>
Wed, 20 Apr 2022 19:24:39 +0200
changeset 49449 cfff73cab721
parent 32570 92bcaef3420b
permissions -rw-r--r--
rebase: add boolean config item rebase.store-source This allows to use rebase without recording a rebase_source extra field. This is useful for example to build a mirror converted from another SCM (such as svn) by converting only new revisions, and then incrementally add them to the destination by pulling from the newly converted (unrelated) repo and rebasing the new revisions onto the last old already stored changeset. Without this patch the rebased changesets would always receive some rebase_source that would depend on the particular history of the conversion process, instead of only depending on the original source revisions. This is used to implement a hg mirror repo of SvarDOS (a partially nonfree but completely redistributable DOS distribution) in the scripts at https://hg.pushbx.org/ecm/svardos.scr/ In particular, cre.sh creates an svn mirror, upd.sh recreates an entire hg repo from the svn mirror (which takes too long to do in a regular job), and akt.sh uses hg convert with the config item convert.svn.startrev to incrementally convert only the two most recent revisions already found in the mirror destination plus any possible new revisions. If any are found, the temporary repo's changesets are pulled into the destination (as changesets from an unrelated repository). Then the changesets corresponding to the new revisions are rebased onto the prior final changeset. (Finally, the two remaining duplicates of the prior head and its parent are stripped from the destination repository.) Without this patch, the particular rebase_source extra field would depend on the order and times at which akt.sh was used, instead of only depending on the source repository. In other words, whatever sequence of upd.sh and akt.sh is used at whatever times, it is desired that the final output repositories always match each other exactly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32329
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     1
# A simple script for opening merge conflicts in editor
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     2
# A loose translation of contrib/editmerge to powershell
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     3
# Please make sure that both editmergeps.bat and editmerge.ps1 are available
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     4
# via %PATH% and use the following Mercurial settings to enable it
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     5
#
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     6
# [ui]
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     7
# editmergeps
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     8
# editmergeps.args=$output
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
     9
# editmergeps.check=changed
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    10
# editmergeps.premerge=keep
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    11
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    12
$file=$args[0]
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    13
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    14
function Get-Lines
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    15
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    16
  Select-String "^<<<<<<" $file | % {"$($_.LineNumber)"}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    17
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    18
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    19
$ed = $Env:HGEDITOR;
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    20
if ($ed -eq $nil)
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    21
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    22
  $ed = $Env:VISUAL;
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    23
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    24
if ($ed -eq $nil)
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    25
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    26
  $ed = $Env:EDITOR;
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    27
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    28
if ($ed -eq $nil)
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    29
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    30
  $ed = $(hg showconfig ui.editor);
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    31
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    32
if ($ed -eq $nil)
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    33
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    34
  Write-Error "merge failed - unable to find editor"
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    35
  exit 1
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    36
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    37
32345
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    38
if (($ed -eq "vim") -or ($ed -eq "emacs") -or `
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    39
    ($ed -eq "nano") -or ($ed -eq "notepad++"))
32329
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    40
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    41
  $lines = Get-Lines
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    42
  $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    43
  $previousline = $nil;
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    44
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    45
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    46
  # open the editor to the first conflict until there are no more
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    47
  # or the user stops editing the file
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    48
  while (($firstline -ne $nil) -and ($firstline -ne $previousline))
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    49
  {
32345
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    50
    if ($ed -eq "notepad++")
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    51
    {
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    52
        $linearg = "-n$firstline"
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    53
    }
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    54
    else
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    55
    {
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    56
        $linearg = "+$firstline"
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    57
    }
a438f5a3bc09 contrib: make editmergeps able to work with notepad++
Kostia Balytskyi <ikostia@fb.com>
parents: 32344
diff changeset
    58
32568
4daf5c18055a contrib: make editmergeps use -NoNewWindow option in Start-Process cmdlet
Kostia Balytskyi <ikostia@fb.com>
parents: 32345
diff changeset
    59
    Start-Process -Wait -NoNewWindow $ed $linearg,$file
32329
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    60
    $previousline = $firstline
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    61
    $lines = Get-Lines
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    62
    $firstline = if ($lines.Length -gt 0) { $lines[0] } else { $nil }
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    63
  }
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    64
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    65
else
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    66
{
32569
04e18be6e188 contrib: fix a bug preventing editmergeps.ps1 from running unknonw editors
Kostia Balytskyi <ikostia@fb.com>
parents: 32568
diff changeset
    67
  & "$ed" $file
32329
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    68
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    69
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    70
$conflicts=Get-Lines
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    71
if ($conflicts.Length -ne 0)
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    72
{
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    73
  Write-Output "merge failed - resolve the conflicts (line $conflicts) then use 'hg resolve --mark'"
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    74
  exit 1
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    75
}
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    76
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    77
exit 0
799615bbf5bf contrib: add editmerge version for powershell
Kostia Balytskyi <ikostia@fb.com>
parents:
diff changeset
    78