Skip to content

Instantly share code, notes, and snippets.

@mig42
Created March 1, 2017 10:30
Show Gist options
  • Save mig42/1c36928d8bd3f09aa9db8be1c8141d6a to your computer and use it in GitHub Desktop.
Save mig42/1c36928d8bd3f09aa9db8be1c8141d6a to your computer and use it in GitHub Desktop.
Powershell script to generate UNIX diff
param (
[Parameter(Mandatory=$true)][string]$SrcRev,
[Parameter(Mandatory=$true)][string]$DstRev,
[bool]$Force
)
function ExtractFileNameFromRev([string]$rev)
{
if ("$rev" -match '^([^:#@]*:)?([^@]*).*$')
{
$matches[2]
return
}
echo "UNKNOWN"
}
function FileExists([string]$File)
{
if ("$File")
{
Test-Path -LiteralPath "$File"
return
}
$false
}
$srcLabel = ExtractFileNameFromRev "$SrcRev"
$dstLabel = ExtractFileNameFromRev "$DstRev"
$srcPath = [io.path]::combine($env:Temp, [guid]::NewGuid())
$dstPath = [io.path]::combine($env:Temp, [guid]::NewGuid())
cm cat "$SrcRev;$srcPath" "$DstRev;$dstPath"
if ($Force -or (FileExists "$srcPath" -and FileExists "$dstPath"))
{
# Download diff and depencencies at http://gnuwin32.sourceforge.net/packages/diffutils.htm
diff -Naur --label "$srcLabel" --label "$dstLabel" "$srcPath" "$dstPath"
}
else
{
echo "Unable to calculate differences"
}
rm -Force "$srcPath","$dstPath" -ErrorAction SilentlyContinue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment