commit-patch/0000755000175000017500000000000013431462444012056 5ustar dimadimacommit-patch/cpanfile0000644000175000017500000000007713431462251013562 0ustar dimadima# -*- perl -*- requires 'IPC::Run'; requires 'App::FatPacker'; commit-patch/commit-patch0000755000175000017500000004027013431462251014370 0ustar dimadima#!/usr/bin/perl -w # Copyright © 2003-2015 David Caldwell # and Jim Radford # This code can be distributed under the terms of the GNU Public License (Version 2 or greater). my $VERSION = '2.6'; use strict; use Cwd qw(abs_path); use IPC::Run; use File::Temp qw(tempfile); use Getopt::Long; use Pod::Usage; my ($dry_run, $verbose); sub run { if ($verbose || $dry_run) { for (@_) { print join ' ', map { $_ =~ / / ? "\"$_\"" : $_ } @$_ if ref $_ eq 'ARRAY'; print " $_ " if ref $_ eq ''; print '[',ref $_,'] ' if ref $_ ne 'ARRAY' && ref $_ ne ''; } print "\n"; } return 1 if $dry_run; IPC::Run::run(@_); } sub trim($) { my $s = shift; $s =~ s/^\s*//; $s =~ s/\s*$//; $s } my %clean; # Rename keys to values on any error (rollback). Unlinks keys on success. my $repo="."; my $amend; my %vc; while (!$vc{name}) { if (-d "$repo/CVS" && $repo eq '.') { %vc = (name => 'cvs', diff => 'cvs diff -Nu', commit => 'cvs commit', message => sub { ('-m', $_[0]) }, message_file => sub { ('-F', $_[0]) }, add => 'cvs add', remove => 'cvs rm', patcharg => '-p0', lsdiffarg => []); } elsif (-d "$repo/.svn") { %vc = (name => 'svn', diff => 'svn diff -x -u', commit => 'svn commit', message => sub { ('-m', $_[0]) }, message_file => sub { ('-F', $_[0]) }, add => 'svn add', remove => 'svn delete', patcharg => '-p0', lsdiffarg => []); } elsif (-d "$repo/_darcs") { %vc = (name => 'darcs', diff => 'darcs diff -u', add => 'darcs add', remove => 'true', commit => 'darcs record --all', amend => 'darcs amend-record --all', patcharg => '-p1', lsdiffarg => [qw(--strip 1)], message => sub { return () if $amend; # Darcs amend doesn't have --logfile, so don't support comments on amend. # Darcs doesn't like multiline -m comments so we have to put the log message into a file and use --logfile. Yuck. #return ('-m', $_[0]); my $message = $_[0]; $message .= "\n" unless $message =~ /\n$/s; # Darcs does screwey stuff when logfile has no trailing \n. my ($message_file, $message_filename) = tempfile("commit-patch-message-XXXXXXXX", UNLINK=>0); print $message_file $message; close $message_file; $clean{$message_filename} = undef; # make sure we delete this file on exit. ("--logfile=$message_filename"); }, message_file => sub { die "Darcs doesn't support --message-file and --amend" if $amend; ("--logfile=$_[0]" ) }); } elsif (-d "$repo/.hg") { %vc = (name => 'hg', diff => 'hg diff', commit => 'hg commit', message => sub { ('-m', $_[0]) }, message_file => sub { ('--logfile', $_[0]) }, add => 'hg addremove', remove => 'true', patcharg => '-p1', lsdiffarg => [qw(--strip 1)]); } elsif (-d "$repo/.bzr") { %vc = (name => 'bzr', diff => 'bzr diff', commit => 'bzr commit', message => sub { ('-m', $_[0]) }, message_file => sub { ('--file', $_[0]) }, add => 'bzr add', remove => 'true', patcharg => '-p0', lsdiffarg => []); chdir $repo; # otherwise commit-partial from within a project subdir fails. } elsif (-d "$repo/.git") { %vc = (name => 'git', diff => 'git diff --relative', # Use --relative here because "git diff | git apply --cached" fails to apply hunks from files not in your current dir tree commit => 'git commit', amend => 'git commit --amend', message => sub { ('-m', $_[0]) }, message_file => sub { ('-F', $_[0]) }, previous_message => sub { my $prev; run([qw(git log -1 --pretty=format:%s%n%b)], '>', \$prev); $prev }); # Git is special cased below. } elsif (-d "$repo/_MTN") { %vc = (name => 'mtn', diff => 'mtn automate content_diff', commit => 'mtn commit', message => sub { ('-m', $_[0]) }, message_file => sub { ('--message-file', $_[0]) }, add => 'mtn add', remove => 'mtn drop', patcharg => '-p0', lsdiffarg => []); } else { $repo.="/.."; printf("Trying back a dir: $repo, abs:%s\n", abs_path($repo)); die "couldn't find repo" if abs_path($repo) eq "/"; } } my $commit_partial = $0 =~ /commit-partial/; my $commit_patch = !$commit_partial; my ($message, $message_filename, $retry); GetOptions("h|help" => sub { pod2usage(1) }, "n|dry-run" => \$dry_run, "a|amend" => \$amend, "v|verbose" => \$verbose, "version" => sub { print "Version $VERSION\n"; exit }, $commit_patch ? ("m|message=s" => \$message, "F|message-file=s" => \$message_filename) : # commit-partial ("r|retry" => \$retry), ) and ($commit_patch && scalar @ARGV <= 1 || $commit_partial) or pod2usage(2); my $patch; if ($commit_patch) { if (scalar @ARGV == 1) { $patch = shift; } else { (my $p, $patch) = tempfile("commit-patch-patch-XXXXXXXX", UNLINK=>0); print $p $_ while (<>); $clean{$patch} = undef; } } my $vc_commit = $amend ? ($vc{amend} || die "$vc{name} does not support amending.\n") : $vc{commit}; # commit-partial creates a patch file for them and launches their editor. if ($commit_partial) { $patch = "commit.$$.patch"; $clean{$patch} = undef; my $previous_message = !$amend ? '' : $vc{previous_message} && trim $vc{previous_message}->(); $message = $previous_message; if ($retry) { use File::Copy; copy("#last-comit-partial.patch", $patch); } else { open PATCH, '>', $patch or die "$patch: $!\n"; print PATCH "$message\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" if defined $message; close PATCH; run([split(/ /,$vc{diff}), @ARGV], '>>', $patch); } system(($ENV{VISUAL} || $ENV{EDITOR} || 'vi')." ".$patch); my $last_patch = "#last-comit-partial.patch"; unlink "$last_patch.3"; rename "$last_patch.2", "$last_patch.3"; rename "$last_patch", "$last_patch.2"; link $patch, $last_patch; if (defined $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 = trim($message); undef $message if $amend && $message eq $previous_message; } die "No commit message, so I'm not going to do anything.\n" if !$amend && $message eq ''; } die "bad patch file: $!" if -z $patch; die "Invalid message" if !$amend && defined $message && $message eq ""; my @message_opt = $message ? $vc{message}->($message) : $message_filename ? $vc{message_file}->($message_filename) : (); # Git pretty much supports what commit-patch does already, so we special case it here. if ($vc{name} eq 'git') { run([qw(git diff --cached --quiet)]) or die "The index is not empty. Cowardly refusing to do anything potentially harmful.\n"; run([qw(git apply --cached), $patch]) or die "Git failed.\n"; run([split(/ /,$vc_commit), @message_opt]) or die "Git failed.\n"; exit; } my ($lsdiff_out, $err); run ["lsdiff", '-s', @{$vc{lsdiffarg}}, $patch], '>', \$lsdiff_out, '2>', \$err or die "lsdiff -s: $! ($err)"; my %lsdiff = map { /^([-+!])\s+(.*)$/ or die "bad lsdiff line: $_\nOut:\n$lsdiff_out"; ( $2 => $1 ) } split(/\n/, $lsdiff_out); my @added = grep { $lsdiff{$_} eq '+' } keys %lsdiff; my @removed = grep { $lsdiff{$_} eq '-' } keys %lsdiff; my @changed = grep { $lsdiff{$_} eq '!' } keys %lsdiff; die "No files in patch" unless scalar %lsdiff; #print "Found $vc{name} in $repo\n"; #printf("files: %s\n", join(",", @files)); for my $f (@changed, @added, @removed) { run ["cp", "-f", $f, "$f.orig.$$"] or die "couldn't make backup of $f: $!" if -f $f; $clean{"$f.orig.$$"} = $f; unlink $f if grep { $_ eq $f } @added; # Needs to be gone so patch can create it } $SIG{PIPE} = $SIG{INT} = $SIG{QUIT} = sub { print "Cleanly aborting..\n"; }; my ($out, $working_patch, $non_committed_patch); run([split(/ /,$vc{diff}), @changed, @removed], '>', \$working_patch, '2>', \$err);# CVS diff dies. Sigh. or die "$err\n"; unless ($working_patch =~ /^\s*$/s) { # Work around an apparent bug in darcs () run(["interdiff", $vc{patcharg}, $patch, '/dev/stdin'], '<', \$working_patch, '>', \$non_committed_patch, '2>', \$err) or die "$err\n"; run([qw"patch -R --force", $vc{patcharg}], '<', \$working_patch, '>', \$out, '2>', \$err) or die "$out\n$err\n"; } run(["patch", $vc{patcharg}], '<', $patch, '>', \$out, '2>', \$err) or die "patch: $out\n$err\n"; run([split(/ /,$vc{add}), @added], '>', \$out, '2>', \$err) or die "$vc{add}: $out\n$err\n" if @added; run([split(/ /,$vc{remove}), @removed], '>', \$out, '2>', \$err) or die "$vc{remove}: $out\n$err\n" if @removed; # Don't capture stdout or stderr because it can be interactive (cough cough darcs) run([split(/ /,$vc_commit), @message_opt, @added, @removed, @changed]) or die "commit failed.\n"; run(["patch", $vc{patcharg}], '<', \$non_committed_patch, '>', \$out, '2>', \$err) or die "patch: $out\n$err\n"; END { return if $dry_run; if ($?) { # Did we die? foreach my $k (grep { $clean{$_} } keys %clean) { rename $k,$clean{$k}; delete $clean{$k} } } foreach my $k (keys %clean) { unlink $k } } =encoding utf-8 =head1 NAME commit-patch - commit patches to I, I, I, I, I, I, or I repositories =head1 SYNOPSIS commit-patch [B<--amend>] [B<-m> I] [B<-F> I] [B<-v>] [B<--dry-run>] [I] commit-partial [B<--amend>] [B<-v>] [B<--dry-run>] [B<--retry>] [I ...] =head1 DESCRIPTION Normally version control systems don't allow fine grained commits. B allows the user to control I what gets committed (or "recorded", in I parlance) by letting the user supply a patch to be committed rather than using the files in the current working directory. If I is not supplied on the command line then the patch will be read from standard input. B is like commit-patch except that it will create a patch from the current changes in the current working directory and launch your editor so that you can edit the patch and the commit message (using the B environment variable, or if that isn't set the B environment variable, or, if I isn't set, B. Any files you specify will be passed to your version control's diff command. B currently supports the following version control systems: B>, B>, B>, B>, B>, B>, and B>. =head1 OPTIONS B<-a>, B<--amend> - Amend a previous commit. Currently only B> and B> support this option. When used with B> it will amend the previous commit. When used with B>, B> will ask you which patch you want to amend. B<-m>, B<--message>=I - An optional I to use as the commit text. If the message is multiple lines then I, I, and I will use the first line as the patch name and the rest as commit details. If the C<-m> option is not specified then the result will be the same as whatever the underlying version control system would do if you didn't specify a message name on the command line. That is, B does not interfere with the patch naming process of the underlying version control system; I will still ask you interactively; I and I will still launch your editor. B<-F>, B<--message-file>=I - You can optionally get the commit message from a file. This is generally only useful for scripting B. B<-v>, B<--verbose> - Turn on debugging. This will print the commands that B is running to get the patch committed. B<-n>, B<--dry-run> - Turn on more paranoid debugging. This will print the commands that B will run to get the patch committed but it won't actually run those commands. B<-r>, B<--retry> - Only available in I. This will reload the last patch that was attempted to be committed into your editor instead of the current changes in the directory. This is for cases where the patch fails to commit for some reason and you want to try to fix it instead of starting over. =head1 DIAGNOSTICS B works by manipulating the working directory using C, C, and the underlying version control system's C. If any part of the process fails, B will attempt to restore the working directory to the state it was before the command was run. Any errors from the underlying version control system or from patch will be printed. =head1 CAVEATS The patch specified on the command line must originate from the same place as the current directory. That is, the following will not work: cvs diff -u > ../a.patch cd .. commit-patch a.patch You B run B from the same directory that the original patch was based from. I, I and I put C and C in front of all the paths in the diff output. Don't worry about this; B takes it into account. =head1 EXAMPLES Typical I usage: cvs diff -u > a.patch emacs a.patch commit-patch a.patch I usage with a message specified: hg diff > a.patch emacs a.patch commit-patch -m "This is a commit message" a.patch I usage with a multi-line message specified: darcs diff -u > a.patch emacs a.patch commit-patch -m 'This is the patch name Here are the patch details' a.patch =head1 AUTHORS =over =item * David Caldwell =item * Jim Radford =back =head1 COPYRIGHT AND LICENSE Copyright © 2003-2015 by David Caldwell and Jim Radford. B is distributed under the GNU General Public License. See the COPYING file in the distribution for more details. =head1 HISTORY B was originally called C and was a bash script written in 2003 by Jim Radford (with David Caldwell in the room drawing the procedure on a white board). David later converted it do C, then integrated them back together into B. I support was then added. At some point David translated from bash into perl because funky bash quoting issues were causing problems with a repository that had a space in one of the directory names. =cut commit-patch/COPYING0000644000175000017500000004310313431462251013106 0ustar dimadima GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. commit-patch/Changes0000644000175000017500000000624213431462251013351 0ustar dimadimacommit-patch (2.6) * Support --amend from the Emacs interface (Dima Kogan) * Fixed a bug with symlinked files in repos (Dima Kogan) * Allow Emacs config option `commit-patch-program` to be a function (Dima Kogan) -- David Caldwell Sun, 03 Feb 2019 00:24:11 -0800 commit-patch (2.5.2) * Fixed dumb bug that caused "make install" to fail. -- David Caldwell Sun, 21 Sep 2014 18:15:04 -0700 commit-patch (2.5.1) * We now use App::Fatpacker to bundle IPC::Run, removing the dependency from the release tarball. * Work around emacs/tramp bug in commit-patch-buffer.el (thanks Dima Kogan ). -- David Caldwell Sun, 21 Sep 2014 17:22:29 -0700 commit-patch (2.5) * Added Monotone support. * Support Subversion version 1.7. * Fixed an issue with git where committing inside a repository's subdirectory would fail. * Fixed some cases where adding and removing files would fail. * Added a small, poor testing infrastructure. -- David Caldwell Wed, 15 May 2013 19:34:42 -0700 commit-patch (2.4) * Added --retry option to commit-partial for retrying failed patches. * Added auto-detect support to commit-patch-buffer. Pass a prefix arg (C--) to make it revert to the old behavior and ask for a patch buffer and directory. -- David Caldwell Sun, 24 Oct 2010 15:23:22 -0700 commit-patch (2.3) * Added Bazaar (bzr) support. * Added amend support (via new --amend flag). It's only supported by git and darcs at the moment. * It now gets rid of unnecessary spaces before and after commit message. * Allowed VISUAL/EDITOR environment variables to have spaces in them. (So that 'VISUAL="emacs -nw" commit-partial' works). * commit-partial now keeps the last few patch/commit-message files around for easy reuse when a commit fails. * Patches can now come from stdin. * commit-patch-buffer.el loads diff-mode on demand for faster emacs startups (Jim Radford ). * commit-patch-buffer.el can commit-patch a file loaded with tramp. * Fixed commit-patch-buffer.el so it works with Emacs 23 (Jonathan Kotta ). * commit-patch-buffer.el only displays commit-patch output when there was an error (Jonathan Kotta ). -- David Caldwell Thu, 18 Mar 2010 20:02:43 -0700 commit-patch (2.2) * Added SVN support from Peter Mack & Joel Hillacre . * Made commit-partial work with git. -- David Caldwell Fri, 16 Jan 2009 17:09:56 -0800 commit-patch (2.1) * Added Git support. * Added "commit-partial". (inspired by Pistos ) * Added --verbose and --dry-run options. * Added --message-file option. (inspired by Pistos ) * Fix lsdiff on CVS sub directories. (thanks: Pistos ) -- David Caldwell Mon, 22 Dec 2008 17:05:14 -0800 commit-patch (2.0) * Release 2.0 (rewritten perl version of cvs-commit-patch) -- David Caldwell Wed, 23 Aug 2006 17:04:33 -0700 commit-patch/README0000644000175000017500000000464713431462251012745 0ustar dimadimacommit-patch - commit patches to Darcs, Git, Mercurial, Bazaar, Monotone, Subversion, or CVS ------------------------------------------------------- PREREQUISITES commit-patch relies on several programs to get the job done: perl - patch - interdiff - cp - Ideally installed on your system already. :-) and, of course, one of: darcs - git - mercurial - bazaar - monotone - subversion - cvs - On Debian/Ubuntu: apt-get install libipc-run-perl patch patchutils On Fedora: yum install perl-IPC-Run patch patchutils On Mac OS X w/ Homebrew brew install patchutils cpan -i IPC::Run commit-patch is known to run on Linux and Mac OS X. It is perl, so ideally it will run anywhere, but we have never tested in other environments, most notably Windows. Use at your own risk. INSTRUCTIONS commit-patch: See the man page or perldoc: man ./commit-patch.1 perldoc commit-patch commit-patch-buffer.el is an emacs interface to commit-patch. It allows you to just hit C-c C-c in any patch buffer to apply and commit only the changes indicated by the patch, regardless of the changes in your working directory. One method of working with commit-patch-buffer is to just M-x vc-diff a file then kill, split or edit the resulting hunks and to then hit C-c C-c to commit the patch. The other is to use PCL cvs mode to tag many files and then to diff them into a buffer which can again be edited and committed. HOMEPAGE AUTHORS o David Caldwell o Jim Radford COPYRIGHT AND LICENSE Copyright © 2003-2015 by David Caldwell and Jim Radford. commit-patch is distributed under the GNU General Public License. See the COPYING file in the distribution for more details. commit-patch/Makefile0000644000175000017500000000275713431462251013525 0ustar dimadimaVERSION := $(shell perl -ne '/VERSION\s*=\s*'"'(.*)'"'/ and print "$$1"' commit-patch) BIN = commit-patch commit-partial MAN = commit-patch.1 commit-partial.1 ELISP = commit-patch-buffer.el DOC = commit-patch.html README COPYING Changes ALL = $(BIN) $(MAN) $(ELISP) $(DOC) all: $(ALL) commit-patch.fat: commit-patch carton exec fatpack pack $< > $@ chmod +x $@ commit-partial: ln -s commit-patch commit-partial commit-patch.1: commit-patch pod2man -c "User Commands" $< > $@ commit-partial.1: ln -s commit-patch.1 commit-partial.1 commit-patch.html: commit-patch pod2html --title="commit-patch Documentation" $< > $@ release: commit-patch-$(VERSION).tar.gz commit-patch-$(VERSION).tar.gz: $(ALL) Makefile commit-patch.fat if ! git diff --quiet -- $^; then tput setab 1; tput setaf 3; /bin/echo -n 'WARNING: Directory is not clean!'; tput sgr0; echo; fi mkdir commit-patch-$(VERSION) rsync -a $^ commit-patch-$(VERSION) mv -f commit-patch-$(VERSION)/commit-patch.fat commit-patch-$(VERSION)/commit-patch tar czf commit-patch-$(VERSION).tar.gz commit-patch-$(VERSION) rm -rf commit-patch-$(VERSION) test: ./test/run-tests .PHONY: test PREFIX=/usr/local install: $(ALL) mkdir -p "$(PREFIX)/bin" mkdir -p "$(PREFIX)/share/man/man1" mkdir -p "$(PREFIX)/share/emacs/site-lisp" mkdir -p "$(PREFIX)/share/doc/commit-patch" cp -a $(BIN) "$(PREFIX)/bin" cp -a $(MAN) "$(PREFIX)/share/man/man1" cp -a $(ELISP) "$(PREFIX)/share/emacs/site-lisp" cp -a $(DOC) "$(PREFIX)/share/doc/commit-patch" commit-patch/test/0000755000175000017500000000000013431462251013031 5ustar dimadimacommit-patch/test/vcs/0000755000175000017500000000000013431462251013624 5ustar dimadimacommit-patch/test/vcs/git.sh0000644000175000017500000000027013431462251014742 0ustar dimadimagit_init () { WD=$1 mkdir -p "$WD" (cd "$WD" && git init) export VC_DIFF="git diff" export VC_RM="true" export DIFF_PREFIX="b/" } git_cleanup () { true } commit-patch/test/vcs/darcs.sh0000644000175000017500000000036013431462251015253 0ustar dimadimadarcs_init () { WD=$1 mkdir -p "$WD" (cd "$WD" && darcs init && echo "Chester McTester" >_darcs/prefs/author) export VC_DIFF="darcs diff" export VC_RM="true" export DIFF_PREFIX="a/" } darcs_cleanup () { true } commit-patch/test/vcs/svn.sh0000644000175000017500000000050113431462251014762 0ustar dimadimasvn_init () { WD=$1 REPO=$2 set -e (cd "$REPO" && svnadmin create test) svn import "$WD" file://"$REPO"/test/trunk -m "Setting up trunk" svn checkout file://"$REPO"/test/trunk "$WD" export VC_DIFF="svn diff" export VC_RM="svn rm" export DIFF_PREFIX="" } svn_cleanup () { true } commit-patch/test/vcs/cvs.sh0000644000175000017500000000037013431462251014753 0ustar dimadimacvs_init () { WD=$1 REPO=$2 export CVSROOT="$REPO" cvs init mkdir "$REPO/test" cvs checkout -d "$WD" test export VC_DIFF="cvs diff -N" export VC_RM="cvs rm" export DIFF_PREFIX="" } cvs_cleanup () { true } commit-patch/test/vcs/mtn.sh0000644000175000017500000000107313431462251014757 0ustar dimadimamtn_init () { WD=$1 REPO=$2 export MTN_KEYDIR=$(mktemp -d "$TESTDIR_ABS/tmp/keydir.XXXXXXX") # Monotone doesns't like the db dir to exist when you init it. [ -d "$REPO" ] && rmdir "$REPO" mtn --keydir "$MTN_KEYDIR" db init --db="$REPO" mtn --keydir "$MTN_KEYDIR" --db="$REPO" --branch=test setup "$WD" (cd "$WD" && mtn automate generate_key commit-patch-automated-tester@example.com '') export VC_DIFF="mtn diff --without-header" export VC_RM="mtn drop" export DIFF_PREFIX="" } mtn_cleanup () { rm -rf "$MTN_KEYDIR" } commit-patch/test/vcs/hg.sh0000644000175000017500000000036313431462251014560 0ustar dimadimahg_init () { WD=$1 mkdir -p "$WD" (cd "$WD" && hg init && (echo "[ui]"; echo "username=Chester McTester") > .hg/hgrc) export VC_DIFF="hg diff" export VC_RM="hg rm" export DIFF_PREFIX="a/" } hg_cleanup () { true } commit-patch/test/vcs/bzr.sh0000644000175000017500000000036613431462251014762 0ustar dimadimabzr_init () { WD=$1 mkdir -p "$WD" (cd "$WD" && bzr init && bzr whoami --branch "Chester McTester ") export VC_DIFF="bzr diff" export VC_RM="true" export DIFF_PREFIX="" } bzr_cleanup () { true } commit-patch/test/run-tests0000755000175000017500000000223613431462251014726 0ustar dimadima#!/bin/bash set -e if [ "$1" == "-v" -o "$1" == "--verbose" ]; then shift set -x export V=--verbose export V_SH=-x fi TESTDIR=$(dirname $0) TESTDIR_ABS=$(cd $TESTDIR && pwd) export COMMIT_PATCH="$TESTDIR_ABS/../commit-patch $V" VCSes=$((cd "$TESTDIR/vcs" && ls -1 *.sh) | sed -e 's/\(.*\)\.sh/\1/') Tests=$(cd "$TESTDIR" && ls -1 *.test) usage () { set +x echo "Usage:" echo " $0 [-v|--verbose] " echo "" echo " Where is one of: $(echo $VCSes)" exit 1; } VCs=${1:-$VCSes} [ "$VCs" == "--help" -o "$VCs" == "-h" ] && usage for vc in "$TESTDIR/vcs/"*.sh; do source "$vc" done run_test () { export VC=$1 TEST=$2 [ -d "$TESTDIR/tmp" ] || mkdir "$TESTDIR/tmp" WD=$(mktemp -d "$TESTDIR_ABS/tmp/wd.XXXXXXX") REPO=$(mktemp -d "$TESTDIR_ABS/tmp/repo.XXXXXXX") ${VC}_init "$WD" "$REPO" if ! (cd "$WD" && sh $V_SH -e "$TESTDIR_ABS/$TEST"); then echo "$VC / $TEST: Test failed." exit 1; fi ${VC}_cleanup "$WD" "$REPO" rm -rf "$WD" rm -rf "$REPO" } for vc in $VCs; do for t in $Tests; do run_test $vc $t done done echo "All tests appear to pass." commit-patch/test/main.test0000644000175000017500000000066213431462251014662 0ustar dimadima# -*- sh -*- echo "initial" > a diff -uN --label /dev/null --label ${DIFF_PREFIX}a /dev/null a > initial.patch || true $COMMIT_PATCH -m "initial" initial.patch echo "1234" >> a $VC_DIFF > changed.patch || true $COMMIT_PATCH -m "changed" changed.patch rm a # Some VCSes won't show diffs for removed files unless you tell it they are removed: $VC_RM a $VC_DIFF > removed.patch || true $COMMIT_PATCH -m "removed" removed.patch commit-patch/commit-patch-buffer.el0000644000175000017500000002205013431462251016227 0ustar dimadima;;; commit-patch-buffer.el --- commit patches to Darcs, Git, Mercurial, Bazaar, Monotone, Subversion, or CVS repositories ;; Copyright 2003-2015 Jim Radford ;; and David Caldwell ;; This code can be distributed under the terms of the GNU Public License (Version 2 or greater). ;; ;; Version: 2.5 ;; ;; Author: Jim Radford ;; David Caldwell ;;; Commentary: ;; commit-patch-buffer provides an Emacs front end to the commit-patch(1) ;; program. Typically the patch to commit would be obtained with vc-diff ;; ("C-c v ="), though any Emacs diff-mode buffer can be committed. ;; ;; Typing "C-c C-c" in a diff-mode buffer kicks off the process and brings ;; up a buffer for the commit comment. After entering a suitable comment, ;; type "C-c C-c" again to finish the commit. If commit-patch-buffer cannot ;; automatically detect the repository directory, it will ask for it ;; interactively. ;; ;; commit-patch-buffer-in-directory is also available: this function skips ;; the automagical repository detection logic if the user wants to directly ;; specify the buffer to commit and directory. ;;; Code: (require 'vc) (require 'log-edit) (defcustom commit-patch-program ;; Prefer a locally installed commit patch over one installed in the PATH. (let* ((this-path (or load-file-name (buffer-file-name))) (local-path (expand-file-name "commit-patch" (file-name-directory this-path)))) (if (file-executable-p local-path) local-path "commit-patch")) "The pathname of the commit-patch executable to use. This could be a string, or a function. If a function, then this is called every time the program path is needed to retrieve the path. The function takes no arguments, but can use variables such as `default-directory'. This is useful to find commit-patch in different places on different machines when using TRAMP." :type '(choice (string :tag "Program path") (function :tag "Function that returns the program path")) :group 'commit-patch) (defun commit-patch--get-program () "Retrieves the path to the commit-patch program. This is the value of the `commit-patch-program' variable, if it is a string, or the value returned by the `commit-patch-program' function, if it is a function." (let ((program (cond ((stringp commit-patch-program) commit-patch-program) ((functionp commit-patch-program) (funcall commit-patch-program)) (t (error "commit-patch-program must be a string or function: %s" commit-patch-program))))) (or program (error "commit-patch-program is nil!")))) ;; Based on vc-git-expanded-log-entry, but don't indent and only grab the full comment using --pretty (defun commit-patch-git-log-comment (revision) (with-temp-buffer (apply 'vc-git-command t nil nil (list "log" "--pretty=format:%B" revision "-1")) (goto-char (point-min)) (unless (eobp) (buffer-string)))) ;; Currently commit-patch only supports --amend with Git and Darcs. ;; But Darcs amend is very interactive, so we don't support it here. (defun commit-patch-last-log-comment (directory) (let ((default-directory directory)) (pcase (vc-responsible-backend directory) (`Git (commit-patch-git-log-comment "HEAD"))))) (defun commit-patch-buffer-in-directory (buffer directory &optional amend) "Commit the patch found in BUFFER by applying it to the repository in DIRECTORY with commit-patch(1). If AMEND is non-nil, we amend the previous commit instead of creating a new one." (interactive "bBuffer to commit: \nDDirectory: \nP") (let* ((patch-files (with-temp-buffer (let ((lsdiff (current-buffer))) (when (eq 0 (with-current-buffer buffer (call-process-region (point-min) (point-max) "lsdiff" nil lsdiff nil))) (split-string (buffer-string)))))) (log-buffer-name (if amend "*amend*" "*commit*")) (f patch-files) visiting-buffers) (while (car f) (let ((buf (find-buffer-visiting (car f)))) (when buf (with-current-buffer buf (vc-buffer-sync)) (add-to-list 'visiting-buffers buf))) (setq f (cdr f))) (if amend (with-current-buffer (get-buffer-create log-buffer-name) (erase-buffer) (insert (or (commit-patch-last-log-comment directory) "")) (goto-char 0))) (log-edit `(lambda () (interactive) (let ((patch (make-temp-file "commit-buffer" nil)) (comment (buffer-string)) (output-buffer (get-buffer-create "*commit-patch*"))) (unwind-protect (progn (with-current-buffer ,buffer (write-region (point-min) (point-max) patch)) (with-current-buffer output-buffer (erase-buffer) (let* ((default-directory ,directory) (status (apply 'process-file (commit-patch--get-program) patch output-buffer nil (append `("-m" ,comment) (if ,amend '("--amend")))))) (if (not (eq status 0)) (progn (window-buffer (display-buffer output-buffer)) (message "Commit patch failed with a status of '%S' (%S)." status patch)) (mapc (lambda (buf) (with-current-buffer buf (vc-resynch-buffer (buffer-file-name buf) 'revert 'noquery) ;; stupid vc-revert-buffer1 doesn't call revert-buffer ;; with preserve-modes which means the CVS version doesn't ;; get updated, so we do it by hand. (run-hooks 'find-file-hooks))) ',visiting-buffers) (message "Patched and %s %S file(s) and reverted %S." (if ,amend "amended" "committed") ,(length patch-files) ,(length visiting-buffers)))))) (delete-file patch)))) nil `((log-edit-listfun . (lambda () ',patch-files))) log-buffer-name))) (defun commit-patch-buffer (&optional arg amend) "Commit the patch in the current buffer, applying it to the repository in the appropriate directory with commit-patch(1). If the current buffer is not in diff-mode or ARG is non-nil then it will ask interactively which buffer to commit and to which directory to commit it. If AMEND is non-nil, we amend the previous commit instead of creating a new one." (interactive "P") (if (and (not arg) (eq major-mode 'diff-mode)) (commit-patch-buffer-in-directory (buffer-name) (autodetect-patch-directory-root) amend) (let ((current-prefix-arg amend)) (call-interactively 'commit-patch-buffer-in-directory)))) (defun commit-patch-buffer-amend (&optional arg) "Commit the patch in the current buffer, applying it to the repository in the appropriate directory with commit-patch(1). If the current buffer is not in diff-mode or ARG is non-nil then it will ask interactively which buffer to commit and to which directory to commit it. This is identical to `commit-patch-buffer' except it amends the last commit by default instead of creating a new one." (interactive "P") (commit-patch-buffer arg t)) (defun autodetect-patch-directory-root () "Tries to autodect where a patch should be committed from using the following algorithm: 1. Grab the path mentioned in the first diff hunk of the current buffer and its buffer's full path. 2. Strip common files/directories from end of paths. 3. Return whatever is left over of buffer's path." (save-excursion (beginning-of-buffer) (diff-hunk-next) ;; Have to be in a hunk or diff-hunk-file-names won't work. (let ((diff-path (reverse (split-string (car (diff-hunk-file-names)) "/"))) (file-path (reverse (split-string (file-chase-links (buffer-file-name (car (diff-find-source-location)))) "/")))) (while (string-equal (car file-path) (car diff-path)) (setq file-path (cdr file-path)) (setq diff-path (cdr diff-path))) ;; The extra "" here adds a / onto the end of our directory. Otherwise call-process (via process-file) ;; calls unhandled-file-name-directory which strips the last part of the path off if it doesn't end with ;; a /. Yes, this took multiple hours to figure out. (combine-and-quote-strings (reverse (cons "" file-path)) "/")))) (eval-after-load 'diff-mode '(progn (setq diff-default-read-only nil) (define-key diff-mode-map "\C-c\C-c" 'commit-patch-buffer) (define-key diff-mode-map "\C-xvv" 'commit-patch-buffer) (define-key diff-mode-map (kbd "C-c C-S-c") 'commit-patch-buffer-amend))) (provide 'commit-patch-buffer) ;;; commit-patch-buffer.el ends here