-sub commit_diff_usage {
- print STDERR "Usage: $0 commit-diff <tree-ish> <tree-ish> [<URL>]\n";
- exit 1
-}
-
-sub commit_diff {
- my $ta = shift or commit_diff_usage();
- my $tb = shift or commit_diff_usage();
- if (!eval { $SVN_URL = shift || file_to_s("$GIT_SVN_DIR/info/url") }) {
- print STDERR "Needed URL or usable git-svn id command-line\n";
- commit_diff_usage();
- }
- my $r = shift;
- unless (defined $r) {
- if (defined $_revision) {
- $r = $_revision
- } else {
- die "-r|--revision is a required argument\n";
- }
- }
- if (defined $_message && defined $_file) {
- print STDERR "Both --message/-m and --file/-F specified ",
- "for the commit message.\n",
- "I have no idea what you mean\n";
- exit 1;
- }
- if (defined $_file) {
- $_message = file_to_s($_file);
- } else {
- $_message ||= get_commit_entry($tb,
- "$GIT_DIR/.svn-commit.tmp.$$")->{log};
- }
- $SVN ||= Git::SVN::Ra->new($SVN_URL);
- if ($r eq 'HEAD') {
- $r = $SVN->get_latest_revnum;
- } elsif ($r !~ /^\d+$/) {
- die "revision argument: $r not understood by git-svn\n";
- }
- my $rev_committed;
- my $pool = SVN::Pool->new;
- my $ed = SVN::Git::Editor->new({ r => $r,
- ra => $SVN->dup,
- svn_path => $SVN->{svn_path}
- },
- $SVN->get_commit_editor($_message,
- sub {
- $rev_committed = $_[0];
- print "Committed $_[0]\n";
- },
- $pool)
- );
- eval {
- my $mods = $ed->apply_diff($ta, $tb);
- if (@$mods == 0) {
- print "No changes\n$ta == $tb\n";
- }
- };
- $pool->clear;
- fatal "$@\n" if $@;
- $_message = $_file = undef;
- return $rev_committed;
-}
-