eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}' & eval 'exec perl -wS "$0" $argv:q' if 0; # Convert git log output to ChangeLog format. my $VERSION = '2012-07-29 06:11'; # UTC # The definition above must lie within the first 8 lines in order # for the Emacs time-stamp write hook (at end) to update it. # If you change this file with Emacs, please let the write hook # do its job. Otherwise, update this string manually. # Copyright (C) 2008-2013 Free Software Foundation, Inc. # 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 3 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, see . # Written by Jim Meyering use strict; use warnings; use Getopt::Long; use POSIX qw(strftime); (my $ME = $0) =~ s|.*/||; # use File::Coda; # http://meyering.net/code/Coda/ END { defined fileno STDOUT or return; close STDOUT and return; warn "$ME: failed to close standard output: $!\n"; $? ||= 1; } sub usage ($) { my ($exit_code) = @_; my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); if ($exit_code != 0) { print $STREAM "Try '$ME --help' for more information.\n"; } else { print $STREAM < ChangeLog $ME -- -n 5 foo > last-5-commits-to-branch-foo SPECIAL SYNTAX: The following types of strings are interpreted specially when they appear at the beginning of a log message line. They are not copied to the output. Copyright-paperwork-exempt: Yes Append the "(tiny change)" notation to the usual "date name email" ChangeLog header to mark a change that does not require a copyright assignment. Co-authored-by: Joe User List the specified name and email address on a second ChangeLog header, denoting a co-author. Signed-off-by: Joe User These lines are simply elided. In a FILE specified via --amend, comment lines (starting with "#") are ignored. FILE must consist of pairs where SHA is a 40-byte SHA1 (alone on a line) referring to a commit in the current project, and CODE refers to one or more consecutive lines of Perl code. Pairs must be separated by one or more blank line. Here is sample input for use with --amend=FILE, from coreutils: 3a169f4c5d9159283548178668d2fae6fced3030 # fix typo in title: s/all tile types/all file types/ 1379ed974f1fa39b12e2ffab18b3f7a607082202 # Due to a bug in vc-dwim, I mis-attributed a patch by Paul to myself. # Change the author to be Paul. Note the escaped "@": s,Jim .*>,Paul Eggert , EOF } exit $exit_code; } # If the string $S is a well-behaved file name, simply return it. # If it contains white space, quotes, etc., quote it, and return the new string. sub shell_quote($) { my ($s) = @_; if ($s =~ m![^\w+/.,-]!) { # Convert each single quote to '\'' $s =~ s/\'/\'\\\'\'/g; # Then single quote the string. $s = "'$s'"; } return $s; } sub quoted_cmd(@) { return join (' ', map {shell_quote $_} @_); } # Parse file F. # Comment lines (starting with "#") are ignored. # F must consist of pairs where SHA is a 40-byte SHA1 # (alone on a line) referring to a commit in the current project, and # CODE refers to one or more consecutive lines of Perl code. # Pairs must be separated by one or more blank line. sub parse_amend_file($) { my ($f) = @_; open F, '<', $f or die "$ME: $f: failed to open for reading: $!\n"; my $fail; my $h = {}; my $in_code = 0; my $sha; while (defined (my $line = )) { $line =~ /^\#/ and next; chomp $line; $line eq '' and $in_code = 0, next; if (!$in_code) { $line =~ /^([0-9a-fA-F]{40})$/ or (warn "$ME: $f:$.: invalid line; expected an SHA1\n"), $fail = 1, next; $sha = lc $1; $in_code = 1; exists $h->{$sha} and (warn "$ME: $f:$.: duplicate SHA1\n"), $fail = 1, next; } else { $h->{$sha} ||= ''; $h->{$sha} .= "$line\n"; } } close F; $fail and exit 1; return $h; } # git_dir_option $SRCDIR # # From $SRCDIR, the --git-dir option to pass to git (none if $SRCDIR # is undef). Return as a list (0 or 1 element). sub git_dir_option($) { my ($srcdir) = @_; my @res = (); if (defined $srcdir) { my $qdir = shell_quote $srcdir; my $cmd = "cd $qdir && git rev-parse --show-toplevel"; my $qcmd = shell_quote $cmd; my $git_dir = qx($cmd); defined $git_di