Received: (at submit) by debbugs.gnu.org; 22 Nov 2019 22:51:44 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 22 17:51:44 2019 Received: from localhost ([127.0.0.1]:55681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1iYHmB-0006gk-Mo for submit <at> debbugs.gnu.org; Fri, 22 Nov 2019 17:51:44 -0500 Received: from lists.gnu.org ([209.51.188.17]:48819) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <karl@HIDDEN>) id 1iYHlu-0006gA-2f for submit <at> debbugs.gnu.org; Fri, 22 Nov 2019 17:51:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45905) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <karl@HIDDEN>) id 1iYHlq-0003hu-Q0 for bug-vc-dwim@HIDDEN; Fri, 22 Nov 2019 17:51:25 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_MED, URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <karl@HIDDEN>) id 1iYHlo-00063g-QZ for bug-vc-dwim@HIDDEN; Fri, 22 Nov 2019 17:51:22 -0500 Received: from freefriends.org ([96.88.95.60]:56020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <karl@HIDDEN>) id 1iYHlo-00062F-F1 for bug-vc-dwim@HIDDEN; Fri, 22 Nov 2019 17:51:20 -0500 X-Envelope-From: karl@HIDDEN X-Envelope-To: <bug-vc-dwim@HIDDEN> Received: from freefriends.org (freefriends.org [96.88.95.60]) by freefriends.org (8.14.7/8.14.7) with ESMTP id xAMMpHHQ004484 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <bug-vc-dwim@HIDDEN>; Fri, 22 Nov 2019 15:51:17 -0700 Received: (from apache@localhost) by freefriends.org (8.14.7/8.14.7/Submit) id xAMMpH9u004483; Fri, 22 Nov 2019 15:51:17 -0700 Date: Fri, 22 Nov 2019 15:51:17 -0700 Message-Id: <201911222251.xAMMpH9u004483@HIDDEN> From: Karl Berry <karl@HIDDEN> To: bug-vc-dwim@HIDDEN Subject: adding --dry-run option to vc-dwim [patch] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 96.88.95.60 X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.4 (--) Possible NEWS entry, under "New features": vc-dwim accepts a new option: --dry-run (-n) Several of the changes are just replacing <code> with if ($dry_run) { print "msg"; } else { <code> } hence they look longer than they actually are. 2019-11-14 Karl Berry <karl@HIDDEN> vc-dwim: New option vc-dwim --dry-run (aka -n). * vc-dwim.pl ($dry_run): new variable. (GetOptions): set it. (run_command): conditionalize system call and INHIBIT_STDOUT. (main): conditionalize initialize operations, rename, symlink. * doc/vc-dwim.texi (vc-dwim Invocation): document it. --- doc/vc-dwim.texi 2019-11-13 17:36:14.920575492 -0800 +++ n.texi 2019-11-17 18:23:06.972699737 -0800 @@ -252,4 +252,8 @@ Perform the commit, too. +@item -n +@itemx --dry-run +Print the commands that would be run instead of running them. + @item --diff Determine which version control system manages the first --- vc-dwim.pl 2019-11-17 18:43:44.673256552 -0800 +++ n.pl 2019-11-21 18:14:13.250781876 -0800 @@ -61,4 +61,5 @@ my $verbose = 0; my $debug = 0; +my $dry_run = 0; sub usage ($) @@ -248,5 +249,5 @@ DIE_UPON_FAILURE => 1, INHIBIT_STDERR => 0, - INHIBIT_STDOUT => 1, + INHIBIT_STDOUT => ! $dry_run, # keep stdout if just printing ); @@ -292,5 +293,11 @@ my $fail = 1; - my $rc = 0xffff & system @cmd; + my $rc; + if ($dry_run) { + print "$ME: would run: @cmd\n"; + $rc = 0; + } else { + $rc = 0xffff & system @cmd; + } # Restore stdout. @@ -734,4 +741,6 @@ 'print-vc-list' => sub { print join (' ', VC::supported_vc_names()), "\n"; exit }, + n => \$dry_run, + 'dry-run' => \$dry_run, debug => \$debug, verbose => \$verbose, @@ -757,13 +766,21 @@ do_at ($adm, sub { - ! (mkdir ('c') || $! == EEXIST) - and die "$ME: failed to create $adm/c: $!\n"; - chdir 'c' or die "$ME: failed to chdir to $adm/c: $!\n"; + if ($dry_run) { + print "$ME: would mkdir 'c' in $adm\n"; + } else { + ! (mkdir ('c') || $! == EEXIST) + and die "$ME: failed to create $adm/c: $!\n"; + chdir 'c' or die "$ME: failed to chdir to $adm/c: $!\n"; + } # touch ChangeLog || die - open FH, '>>', $cl - or die "$ME: failed to open '$cl' for writing: $!\n"; - close FH - or die "$ME: failed to write '$cl': $!\n"; + if ($dry_run) { + print "$ME: would touch $cl in $adm\n"; + } else { + open FH, '>>', $cl + or die "$ME: failed to open '$cl' for writing: $!\n"; + close FH + or die "$ME: failed to write '$cl': $!\n"; + } # Initialize the git repo, add ChangeLog and commit it. @@ -775,11 +792,21 @@ # If a ChangeLog file exists in the current directory, rename it - # to ChangeLog~, deliberately ignoring any rename failure. - rename $cl, "$cl~"; + # deliberately ignoring any rename failure. (But only report the + # rename for dry runs if it does exist.) + my $cl_top = "../../$cl"; + if ($dry_run && -e $cl_top) { + print "$ME: would rename($cl_top, $cl_top~)\n"; + } else { + rename $cl_top, "$cl_top~"; + } # Create the top-level ChangeLog symlink into $adm/c: my $cl_sub = "$adm/c/$cl"; - symlink $cl_sub, $cl - or die "$ME: failed to create symlink, $cl, to $cl_sub: $!\n"; + if ($dry_run) { + print "$ME: would symlink($cl_sub, $cl_top)\n"; + } else { + symlink $cl_sub, $cl_top + or die "$ME: failed to create symlink, $cl, to $cl_sub: $!\n"; + } exit 0; @@ -799,5 +826,10 @@ and verbose_cmd \@cmd; - exec @cmd; + if ($dry_run) { + print "$ME: would run: @cmd\n"; + exit 0; + } else { + exec @cmd; + } exit 1; }
Karl Berry <karl@HIDDEN>
:bug-vc-dwim@HIDDEN
.
Full text available.bug-vc-dwim@HIDDEN
:bug#38334
; Package vc-dwim
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.