summaryrefslogtreecommitdiffstats
path: root/svn-commit-git-patch
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-06-14 14:45:10 +0200
committerFlorian Pritz <bluewind@xinu.at>2019-06-14 14:45:10 +0200
commit5a43c68ff8d3be83a14d736b6f45d88ab08d02ac (patch)
tree9f7ea667239e16a584384af88430b21bf4c3ec48 /svn-commit-git-patch
parent6677b0b33fb573ee6a05e1caf16ca545d771993f (diff)
downloadbin-5a43c68ff8d3be83a14d736b6f45d88ab08d02ac.tar.gz
bin-5a43c68ff8d3be83a14d736b6f45d88ab08d02ac.tar.xz
Add svn-commit-git-patch
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'svn-commit-git-patch')
-rwxr-xr-xsvn-commit-git-patch53
1 files changed, 53 insertions, 0 deletions
diff --git a/svn-commit-git-patch b/svn-commit-git-patch
new file mode 100755
index 0000000..54b345d
--- /dev/null
+++ b/svn-commit-git-patch
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use MIME::Words;
+
+=head1 DESCRIPTION
+
+Take a patch made by git-format-patch (e.g. against a git-svn clone of a
+repository) and apply it to an svn repository. Tries to keep the commit subject
+and message. The git commit author and the git commmit date are put into the
+svn commmit message.
+
+This could probably also be done by using `git svn dcommit`, but then I'd have
+to set up/learn git-svn. Doing it like this is easier for such a simple
+usecase. Also, writing short scripts is fun!
+
+=cut
+
+if (@ARGV < 1) {
+ print "usage: svn-commit-git-patch <patchfile>\n";
+ exit 1;
+}
+
+my $patchfile = $ARGV[0] // die "<patchfile> not set";
+
+my $subject;
+my $message = '';
+
+open my $fh, '<', $patchfile;
+while (my $line = <$fh>) {
+ last if $line =~ /^---$/;
+
+ # TODO: does this need the whole message or is it enough to pass a single
+ # line? what about potential multiline headers? no idea if git creates
+ # those
+ $line = MIME::Words::decode_mimewords($line);
+
+ # TODO: parse multiline subject "headers" correctly. no idea if git creates those
+ if ($line =~ /^Subject: (?:\[PATCH \d+\/\d+\] )?(.*)$/) {
+ $subject = $1;
+ } elsif ($line =~ /^From [a-f0-9]{40} Mon Sep 17 00:00:00 2001$/) {
+ next;
+ } else {
+ $message .= $line;
+ }
+}
+
+$message = "$subject\n\n$message";
+
+system(qw(svn patch --strip 1), $patchfile);
+system(qw(svn commit -m), $message);