From d5d16cfcc1db1a48eeac674a268734039fa5a976 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 22 Dec 2008 16:37:35 -0800 Subject: [PATCH] Add commit-partial. This command does the diff for you, launches your editor and lets you edit the diff and the commit comment in one file. Inspired by Pistos . --- Makefile | 7 +++++-- commit-patch | 48 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a6b3ef2..68cb25d 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,14 @@ VERSION=2.0 -all: executable commit-patch.1 +all: executable commit-partial commit-patch.1 # Darcs loses the x bit. :-( executable: chmod +x commit-patch +commit-partial: + ln -s commit-patch commit-partial + commit-patch.1: commit-patch pod2man -c "User Commands" $< > $@ @@ -14,7 +17,7 @@ commit-patch.html: commit-patch release: commit-patch-$(VERSION) -commit-patch-$(VERSION): commit-patch commit-patch-buffer.el commit-patch.1 Makefile README COPYING +commit-patch-$(VERSION): commit-patch commit-partial commit-patch-buffer.el commit-patch.1 Makefile README COPYING mkdir commit-patch-$(VERSION) cp -p $^ commit-patch-$(VERSION) tar czf commit-patch-$(VERSION).tar.gz commit-patch-$(VERSION) diff --git a/commit-patch b/commit-patch index 17da65c..9f3fa9d 100755 --- a/commit-patch +++ b/commit-patch @@ -81,14 +81,52 @@ while (!$vc{name}) { } } +my $commit_partial = $0 =~ /commit-partial/; +my $commit_patch = !$commit_partial; + my ($message, $message_filename); -GetOptions("m|message=s" => \$message, - "F|message-file=s" => \$message_filename, - "h|help" => sub { pod2usage(1) }, +GetOptions("h|help" => sub { pod2usage(1) }, "n|dry-run" => \$dry_run, "v|verbose" => \$verbose, - ) and scalar @ARGV == 1 or pod2usage(2); -my $patch = shift; + $commit_patch ? + ("m|message=s" => \$message, + "F|message-file=s" => \$message_filename) + : # commit-partial + (), + ) and (scalar @ARGV == 1 || $commit_partial) or pod2usage(2); +my $patch; +$patch = shift if $commit_patch; + +# commit-partial creates a patch file for them and launches their editor. +if ($commit_partial) { + $patch = "commit.$$.patch"; + $clean{$patch} = undef; + + open PATCH, '>', $patch or die "$patch: $!\n"; + print PATCH "\n", + "# Enter your commit comment above and edit your patch below.\n", + "# (Lines starting with # will be stripped and leading and trailing whitespace removed).\n", + "# An empty comment will cancel the operation.\n", + "==END_COMMENT==\n"; + close PATCH; + + run([split(/ /,$vc{diff}), @ARGV], '>>', $patch); + system($ENV{VISUAL} || $ENV{EDITOR} || 'vi', $patch); + + $message = ''; + open PATCH, '<', $patch or die "couldn't read $patch: $!\n"; + while () { + next if /^\#/; + goto finished if /^==END_COMMENT==$/; + $message .= $_; + } + die "Couldn't find comment terminator (==END_COMMENT==)\n"; + finished: + $message =~ s/^\s*//; + $message =~ s/\s*$//; + + die "No commit message, so I'm not going to do anything.\n" if $message eq ''; +} die "bad patch file: $!" if -z $patch; die "Invalid message" if defined $message && $message eq ""; -- 2.51.2