Skip to content

Instantly share code, notes, and snippets.

@rajatjindal
Created August 26, 2022 06:44
Show Gist options
  • Select an option

  • Save rajatjindal/e07890f5da256c5e76b7bf18173b19cd to your computer and use it in GitHub Desktop.

Select an option

Save rajatjindal/e07890f5da256c5e76b7bf18173b19cd to your computer and use it in GitHub Desktop.
generate crucible compatible diff from git
#!/usr/bin/perl
use strict;
use warnings;
my $gitrev = $ARGV[0];
if (!$gitrev) {
die "usage: gitdiff <a51335c5c5e40fad2b788cdea1b2f7bba6c229eb>\n";
}
my $svnrev = `git show $gitrev | grep git-svn-id | awk -F'\@' '{print \$2}' | awk '{print \$1}'`;
$svnrev =~ s/^\s+|\s+$//g;
my $origdiff = `git diff $gitrev`;
my $time = time() * 1000;
my $newdiff = $origdiff;
my $seperator = "<+>UTF-8\n===================================================================";
$newdiff =~ s!diff --git a/.* b/(.*)!Index: $1!g;
$newdiff =~ s!index .* \d{6}!$seperator!g;
$newdiff =~ s!(---.*)!$1 (revision $svnrev)!g;
$newdiff =~ s!(\+\+\+.*)!$1 (date $time)!g;
print $newdiff;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment