From c2f3f60583a1c276f8ac6e01d14b5ffb7e0bcc13 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 10 Feb 2020 08:02:47 -0700 Subject: [PATCH] Avoid changing directory when generating the ChangeLog file. Instead, pass the repo path to either hg or log2cl.pl --- Makefile.in | 14 +++++++------- scripts/log2cl.pl | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index 75928002d..52038e384 100644 --- a/Makefile.in +++ b/Makefile.in @@ -23,7 +23,7 @@ abs_top_srcdir = @abs_top_srcdir@ top_builddir = @top_builddir@ abs_top_builddir = @abs_top_builddir@ devdir = @devdir@ -scriptdir = $(abs_top_srcdir)/scripts +scriptdir = $(top_srcdir)/scripts # Installation paths for package building prefix = @prefix@ @@ -222,16 +222,16 @@ depend: siglist.c signame.c --file $(top_builddir)/src/Makefile ChangeLog: - if test -d $(srcdir)/.hg && cd $(srcdir); then \ - if hg log --style=changelog -r "sort(branch(.) or follow(), -date)" > $@.tmp; then \ - mv -f $@.tmp $@; \ + if test -d $(srcdir)/.hg; then \ + if hg log -R $(srcdir) --style=changelog -r "sort(branch(.) or follow(), -date)" > $@.tmp; then \ + mv -f $@.tmp $(srcdir)/$@; \ else \ rm -f $@.tmp; \ fi; \ - elif test -d $(srcdir)/.git && cd $(srcdir); then \ - $(scriptdir)/log2cl.pl -b master > $@; \ + elif test -d $(srcdir)/.git; then \ + $(scriptdir)/log2cl.pl -R $(srcdir)/.git > $(srcdir)/$@; \ else \ - echo "ChangeLog data not available" > $@; \ + echo "ChangeLog data not available" > $(srcdir)/$@; \ fi config.status: diff --git a/scripts/log2cl.pl b/scripts/log2cl.pl index fe0c7906d..90f23f482 100755 --- a/scripts/log2cl.pl +++ b/scripts/log2cl.pl @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: ISC # -# Copyright (c) 2017 Todd C. Miller +# Copyright (c) 2017, 2020 Todd C. Miller # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -19,10 +19,23 @@ # Simple script to massage "git log" output into a GNU style ChangeLog. # The goal is to emulate "hg log --style=changelog" via perl format. +use Getopt::Std; +use strict; use warnings; +# Git log format: author date, author name, author email +# abbreviated commit hash +# raw commit body my $format="%ad %aN <%aE>%n%h%n%B%n"; -my @cmd = ("git", "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV); + +# Parse options and build up "git log" command +my @cmd = ( "git" ); +my %opts; +getopts('b:R:', \%opts); +push(@cmd, "-b", $opts{"b"}) if exists $opts{"b"}; +push(@cmd, "--git-dir", $opts{"R"}) if exists $opts{"R"}; +push(@cmd, "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV); + open(LOG, '-|', @cmd) || die "$0: unable to run git log: $!"; my $hash;