Created
November 26, 2012 14:39
-
-
Save SimonJWin/4148543 to your computer and use it in GitHub Desktop.
Remove blank svn:mergeinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
#*****************************************************************************# | |
#* Deletes svn:mergeinfo that contains no data. *# | |
#* *# | |
#* Run from a working copy. Does not commit changes. *# | |
#*****************************************************************************# | |
use strict; | |
use XML::Simple; | |
use Getopt::Long; | |
#*****************************************************************************# | |
#* Options. *# | |
#*****************************************************************************# | |
my $dryRun = ""; | |
GetOptions("dry-run" => \$dryRun); | |
#*****************************************************************************# | |
#* Do an SVN propget for the mergeinfo property. *# | |
#*****************************************************************************# | |
my $getCommand = "svn pg -R --xml svn:mergeinfo"; | |
my $xmlString = `$getCommand`; | |
#*****************************************************************************# | |
#* Read the XML generated. *# | |
#*****************************************************************************# | |
my $xml = new XML::Simple; | |
my $propertyInfo = $xml->XMLin($xmlString); | |
#*****************************************************************************# | |
#* List of the files found. *# | |
#*****************************************************************************# | |
my @files = @{$propertyInfo->{'target'}}; | |
#*****************************************************************************# | |
#* Loop over files, keeping count of how many there are. *# | |
#*****************************************************************************# | |
my $countNullMergeinfo = 0; | |
foreach my $file (@files) | |
{ | |
#***************************************************************************# | |
#* Store the mergeinfo data (if any) and file path. *# | |
#***************************************************************************# | |
die "Unexpected XML output" unless exists($file->{"path"}); | |
die "Unexpected XML output" unless exists($file->{"property"}); | |
my $filePath = $file->{"path"}; | |
my $hasActualMergeinfo = exists($file->{"property"}->{"content"}); | |
my $mergeinfo; | |
$mergeinfo = $file->{"property"}->{"content"} if ($hasActualMergeinfo); | |
#***************************************************************************# | |
#* If the file doesn't actually have any mergeinfo... *# | |
#***************************************************************************# | |
if (! $hasActualMergeinfo) | |
{ | |
#*************************************************************************# | |
#* ... delete the mergeinfo property! *# | |
#*************************************************************************# | |
if ($dryRun) | |
{ | |
print "- File " . $filePath . "\n"; | |
} | |
else | |
{ | |
system("svn propdel svn:mergeinfo " . $filePath); | |
} | |
$countNullMergeinfo++; | |
} | |
} | |
print "Deleted mergeinfo from $countNullMergeinfo files\n"; | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment