Proper support for attributing log message.

This change allows for proper use of a regex to find attributions made
in a log message.
This commit is contained in:
Bradley M. Kuhn 2016-04-28 20:52:29 -07:00
parent 2ae7968eee
commit bb4c940b26

View file

@ -22,19 +22,27 @@
# The goal in this script is to take a large Git repostiory and find a
# simple list of all commit ids that match certain criteria, specifically,
# either an Author: field or
# either an Author: field or if they are mentioned in the patch.
# The recommended ATTRIBUTING_LOG_MESSAGE_REGEX is something like this:
# The initial implementation looks
# (Submitted\s+by|original\s+patch|patch\s+(from|by)|originally\s+(from|by)).*
# The idea is this: It's quite common in older times for someone to commit
# on behalf of someone else, where the Author: field reads a particular
# author, but the log message says that someone else wrote it. We're
# looking for a specific author, but we want to eliminate those commits
# where that Author attributed them to someone else, and include those
# commits where someone else indicated that our sought author actually wrote
# the patch.
use Git::Repository 'Log';
if (@ARGV != 3 and @ARGV != 2 and @ARGV != 4) {
print "usage: $0 <GIT_REPOSITORY_PATH> ", "<AUTHOR_NAME_REGEX> [<LOG_MESSAGE_REGEX>] [<VERBOSE_LEVEL>]\n";
print "usage: $0 <GIT_REPOSITORY_PATH> ", "<AUTHOR_NAME_REGEX> [<ATTRIBUTING_LOG_MESSAGE_REGEX>] [<VERBOSE_LEVEL>]\n";
exit 1;
}
my($GIT_REPOSITORY_PATH, $AUTHOR_NAME_REGEX, $LOG_MESSAGE_REGEX, $VERBOSE) = @ARGV;
my($GIT_REPOSITORY_PATH, $AUTHOR_NAME_REGEX, $ATTRIBUTING_LOG_MESSAGE_REGEX, $VERBOSE) = @ARGV;
$VERBOSE = 0 if not defined $VERBOSE;
my $gitRepository = Git::Repository->new(git_dir => $GIT_REPOSITORY_PATH);
@ -43,7 +51,17 @@ my $logIterator = $gitRepository->log();
while ( my $gitLog = $logIterator->next() ) {
my $author = $gitLog->author();
my $message = $gitLog->message();
if ($author =~ /$AUTHOR_NAME_REGEX/im or (defined $LOG_MESSAGE_REGEX and $message =~ /$LOG_MESSAGE_REGEX/im)) {
my $includeThis = 0;
if ($author =~ /$AUTHOR_NAME_REGEX/im) {
# Include all Author: lines of our author, but not if they attributed to
# someone other than the Author in question
$includeThis = 1 unless (defined $ATTRIBUTING_LOG_MESSAGE_REGEX
and $message =~ /$ATTRIBUTING_LOG_MESSAGE_REGEX/im
and $message !~ /$ATTRIBUTING_LOG_MESSAGE_REGEX$AUTHOR_NAME_REGEX/im);
} elsif (defined $ATTRIBUTING_LOG_MESSAGE_REGEX and $message =~ /$ATTRIBUTING_LOG_MESSAGE_REGEX$AUTHOR_NAME_REGEX/im) {
$includeThis = 1;
}
if ($includeThis) {
print STDERR "Including: ", $gitLog->commit(), "\n", "Author: $author", "\n\n", $message, "#" x 72, "\n"
if $VERBOSE;
print $gitLog->commit(), "\n";