From 693dce9e74df3d069836100e6c72139994f01072 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Tue, 21 Apr 2020 17:22:12 +0100 Subject: [PATCH] Implemented merging properties rather than replacing them --- .gitignore | 1 + ue4-svn-setup.ps1 | 59 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba698c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/launch.json diff --git a/ue4-svn-setup.ps1 b/ue4-svn-setup.ps1 index dde0e60..fe68fe5 100644 --- a/ue4-svn-setup.ps1 +++ b/ue4-svn-setup.ps1 @@ -96,7 +96,64 @@ function Set-Svn-Props { [string]$path ) - # TODO implement merge + if (-not $overwriteprops) { + # We need to merge our props with whatever is already present + # Can't believe SVN doesn't have a command for this (facepalm) + $oldvalues = $(svn propget $propname $path) + $oldarray = $oldvalues -split "\r?\n" + $newarray = $values -split "\r?\n" + # remove duplicates & Empties and sort both arrays so we can insert + $oldarray = $oldarray | Where-Object {$_} | Select-Object -Unique | Sort-Object + $newarray = $newarray | Where-Object {$_} | Select-Object -Unique | Sort-Object + # create modifiable list for merged + $finallist = [System.Collections.ArrayList]@() + $oldidx = 0 + foreach ($newitem in $newarray) { + # If this is a X = Y row, then we only match the X part + $match = $newitem + $iskeyvalue = $($newitem -contains "=") + if ($iskeyvalue) { + $match = $newitem.split("=")[0].trim() + } + + $insertednewitem = $false + while (-not $insertednewitem) { + if ($oldidx -lt $oldarray.Length) { + $olditem = $oldarray[$oldidx] + $oldmatch = $olditem + if ($iskeyvalue) { + $oldmatch = $olditem.split("=")[0].trim() + } + + if ($match -eq $oldmatch) { + # use new value + $finallist.Add($newitem) + ++$oldidx + } elseif ($match -gt $oldmatch) { + $finallist.Add($olditem) + ++$oldidx + } else { + $finallist.Add($newitem) + $insertednewitem = $true + } + } else { + # run out of old items, just append new + $finallist.Add($newitem) + $insertednewitem = $true + } + } + } + while ($oldidx -lt $oldarray.Length) { + ## Add any trailing old items + $finallist.Add($oldarray[$oldidx++]) + } + + # Convert to final values + $values = $($finallist -join "`n") + + Write-Verbose "Merged values for $propname on '$path': `n$values" + } + if ($dryrun) { Write-Output "PROPS: Would have set $propname on '$path' to: `n$values" } else {