qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 44/50] scripts: let checkpatch.pl process an entire GIT branch
Date: Tue, 19 Sep 2017 14:29:33 +0200	[thread overview]
Message-ID: <1505824179-21541-45-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1505824179-21541-1-git-send-email-pbonzini@redhat.com>

From: "Daniel P. Berrange" <berrange@redhat.com>

Currently before submitting a series, devs should run checkpatch.pl
across each patch to be submitted. This can be automated using a
command such as:

  git rebase -i master -x 'git show | ./scripts/checkpatch.pl -'

This is rather long winded to type, so this patch introduces a way
to tell checkpatch.pl to validate a series of GIT revisions.

There are now three modes it can operate in 1) check a patch 2) check a source
file, or 3) check a git branch.

If no flags are given, the mode is determined by checking the args passed to
the command. If the args contain a literal ".." it is treated as a GIT revision
list. If the args end in ".patch" or equal "-" it is treated as a patch file.
Otherwise it is treated as a source file.

This automatic guessing can be overridden using --[no-]patch --[no-]file or
--[no-]branch

For example to check a GIT revision list:

    $ ./scripts/checkpatch.pl master..
    total: 0 errors, 0 warnings, 297 lines checked

    b886d352a2bf58f0996471fb3991a138373a2957 has no obvious style problems and is ready for submission.
    total: 0 errors, 0 warnings, 182 lines checked

    2a731f9a9ce145e0e0df6d42dd2a3ce4dfc543fa has no obvious style problems and is ready for submission.
    total: 0 errors, 0 warnings, 102 lines checked

    11844169bcc0c8ed4449eb3744a69877ed329dd7 has no obvious style problems and is ready for submission.

If a genuine patch filename contains the characters '..' it is
possible to force interpretation of the arg as a patch

  $ ./scripts/checkpatch.pl --patch master..

will force it to load a patch file called "master..", or equivalently

  $ ./scripts/checkpatch.pl --no-branch master..

will simply turn off guessing of GIT revision lists.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <20170913091000.9005-1-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/checkpatch.pl | 138 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 111 insertions(+), 27 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index fa47807..28d71b3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -18,11 +18,12 @@ use Getopt::Long qw(:config no_auto_abbrev);
 my $quiet = 0;
 my $tree = 1;
 my $chk_signoff = 1;
-my $chk_patch = 1;
+my $chk_patch = undef;
+my $chk_branch = undef;
 my $tst_only;
 my $emacs = 0;
 my $terse = 0;
-my $file = 0;
+my $file = undef;
 my $no_warnings = 0;
 my $summary = 1;
 my $mailback = 0;
@@ -35,14 +36,19 @@ sub help {
 	my ($exitcode) = @_;
 
 	print << "EOM";
-Usage: $P [OPTION]... [FILE]...
+Usage:
+
+    $P [OPTION]... [FILE]...
+    $P [OPTION]... [GIT-REV-LIST]
+
 Version: $V
 
 Options:
   -q, --quiet                quiet
   --no-tree                  run without a kernel tree
   --no-signoff               do not check for 'Signed-off-by' line
-  --patch                    treat FILE as patchfile (default)
+  --patch                    treat FILE as patchfile
+  --branch                   treat args as GIT revision list
   --emacs                    emacs compile window format
   --terse                    one line per report
   -f, --file                 treat FILE as regular source file
@@ -69,6 +75,7 @@ GetOptions(
 	'tree!'		=> \$tree,
 	'signoff!'	=> \$chk_signoff,
 	'patch!'	=> \$chk_patch,
+	'branch!'	=> \$chk_branch,
 	'emacs!'	=> \$emacs,
 	'terse!'	=> \$terse,
 	'f|file!'	=> \$file,
@@ -93,6 +100,49 @@ if ($#ARGV < 0) {
 	exit(1);
 }
 
+if (!defined $chk_branch && !defined $chk_patch && !defined $file) {
+	$chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0;
+	$chk_patch = $chk_branch ? 0 :
+		$ARGV[0] =~ /\.patch$/ || $ARGV[0] eq "-" ? 1 : 0;
+	$file = $chk_branch || $chk_patch ? 0 : 1;
+} elsif (!defined $chk_branch && !defined $chk_patch) {
+	if ($file) {
+		$chk_branch = $chk_patch = 0;
+	} else {
+		$chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0;
+		$chk_patch = $chk_branch ? 0 : 1;
+	}
+} elsif (!defined $chk_branch && !defined $file) {
+	if ($chk_patch) {
+		$chk_branch = $file = 0;
+	} else {
+		$chk_branch = $ARGV[0] =~ /\.\./ ? 1 : 0;
+		$file = $chk_branch ? 0 : 1;
+	}
+} elsif (!defined $chk_patch && !defined $file) {
+	if ($chk_branch) {
+		$chk_patch = $file = 0;
+	} else {
+		$chk_patch = $ARGV[0] =~ /\.patch$/ || $ARGV[0] eq "-" ? 1 : 0;
+		$file = $chk_patch ? 0 : 1;
+	}
+} elsif (!defined $chk_branch) {
+	$chk_branch = $chk_patch || $file ? 0 : 1;
+} elsif (!defined $chk_patch) {
+	$chk_patch = $chk_branch || $file ? 0 : 1;
+} elsif (!defined $file) {
+	$file = $chk_patch || $chk_branch ? 0 : 1;
+}
+
+if (($chk_patch && $chk_branch) ||
+    ($chk_patch && $file) ||
+    ($chk_branch && $file)) {
+	die "Only one of --file, --branch, --patch is permitted\n";
+}
+if (!$chk_patch && !$chk_branch && !$file) {
+	die "One of --file, --branch, --patch is required\n";
+}
+
 my $dbg_values = 0;
 my $dbg_possible = 0;
 my $dbg_type = 0;
@@ -251,32 +301,66 @@ $chk_signoff = 0 if ($file);
 my @rawlines = ();
 my @lines = ();
 my $vname;
-for my $filename (@ARGV) {
-	my $FILE;
-	if ($file) {
-		open($FILE, '-|', "diff -u /dev/null $filename") ||
-			die "$P: $filename: diff failed - $!\n";
-	} elsif ($filename eq '-') {
-		open($FILE, '<&STDIN');
-	} else {
-		open($FILE, '<', "$filename") ||
-			die "$P: $filename: open failed - $!\n";
-	}
-	if ($filename eq '-') {
-		$vname = 'Your patch';
-	} else {
-		$vname = $filename;
-	}
-	while (<$FILE>) {
+if ($chk_branch) {
+	my @patches;
+	my $HASH;
+	open($HASH, "-|", "git", "log", "--format=%H", $ARGV[0]) ||
+		die "$P: git log --format=%H $ARGV[0] failed - $!\n";
+
+	while (<$HASH>) {
 		chomp;
-		push(@rawlines, $_);
+		push @patches, $_;
+	}
+
+	close $HASH;
+
+	die "$P: no revisions returned for revlist '$chk_branch'\n"
+	    unless @patches;
+
+	for my $hash (@patches) {
+		my $FILE;
+		open($FILE, '-|', "git", "show", $hash) ||
+			die "$P: git show $hash - $!\n";
+		$vname = $hash;
+		while (<$FILE>) {
+			chomp;
+			push(@rawlines, $_);
+		}
+		close($FILE);
+		if (!process($hash)) {
+			$exit = 1;
+		}
+		@rawlines = ();
+		@lines = ();
 	}
-	close($FILE);
-	if (!process($filename)) {
-		$exit = 1;
+} else {
+	for my $filename (@ARGV) {
+		my $FILE;
+		if ($file) {
+			open($FILE, '-|', "diff -u /dev/null $filename") ||
+				die "$P: $filename: diff failed - $!\n";
+		} elsif ($filename eq '-') {
+			open($FILE, '<&STDIN');
+		} else {
+			open($FILE, '<', "$filename") ||
+				die "$P: $filename: open failed - $!\n";
+		}
+		if ($filename eq '-') {
+			$vname = 'Your patch';
+		} else {
+			$vname = $filename;
+		}
+		while (<$FILE>) {
+			chomp;
+			push(@rawlines, $_);
+		}
+		close($FILE);
+		if (!process($filename)) {
+			$exit = 1;
+		}
+		@rawlines = ();
+		@lines = ();
 	}
-	@rawlines = ();
-	@lines = ();
 }
 
 exit($exit);
-- 
1.8.3.1

  parent reply	other threads:[~2017-09-19 12:30 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 12:28 [Qemu-devel] [PULL 00/50] Misc patches for 2017-09-19 Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 01/50] target/i386: fix pmovsx/pmovzx in-place operations Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 02/50] target/i386: set rip_offset for further SSE instructions Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 03/50] target/i386: fix packusdw in-place operation Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 04/50] target/i386: fix pcmpxstrx substring search Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 05/50] target/i386: fix phminposuw in-place operation Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 06/50] virtio-scsi: Add virtqueue_size parameter allowing virtqueue size to be set Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 07/50] scsi-bus: correct responses for INQUIRY and REQUEST SENSE Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 08/50] scsi: Refactor scsi sense interpreting code Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 09/50] scsi: Improve scsi_sense_to_errno Paolo Bonzini
2017-09-19 12:28 ` [Qemu-devel] [PULL 10/50] scsi: Introduce scsi_sense_buf_to_errno Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 11/50] scsi-block: Support rerror/werror Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 12/50] scsi: rename scsi_build_sense to scsi_convert_sense Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 13/50] scsi: move non-emulation specific code to scsi/ Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 14/50] scsi: introduce scsi_build_sense Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 15/50] scsi: introduce sg_io_sense_from_errno Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 16/50] scsi: move block/scsi.h to include/scsi/constants.h Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 17/50] MAINTAINERS: update mail address for NVDIMM Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 18/50] i386/kvm: use a switch statement for MSR detection Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 19/50] i386/kvm: set tsc_khz before configuring Hyper-V CPUID Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 20/50] i386/kvm: introduce tsc_is_stable_and_known() Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 21/50] i386/kvm: advertise Hyper-V frequency MSRs Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 22/50] MAINTAINERS: update email, add missing test entry for megasas Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 23/50] memory: Rename queue to mrqueue (memory region queue) Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 24/50] scsi/esp: Rename the ESP macro to ESP_STATE Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 25/50] multiboot: validate multiboot header address values Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 26/50] kvm: require JOIN_MEMORY_REGIONS_WORKS Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 27/50] kvm: factor out alignment of memory section Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 28/50] kvm: use start + size for memory ranges Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 29/50] kvm: we never have overlapping slots in kvm_set_phys_mem() Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 30/50] kvm: kvm_log_start/stop are only called with known sections Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 31/50] kvm: kvm_log_sync() is only called with known memory sections Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 32/50] test-qga: add missing qemu-ga tool dependency Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 33/50] hw/i386: Improve some of the warning messages Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 34/50] Convert remaining error_report() to warn_report() Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 35/50] Convert single line fprintf(.../n) " Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 36/50] Convert multi-line fprintf() " Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 37/50] General warn report fixups Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 38/50] target/mips: Convert VM clock update prints to warn_report Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 39/50] Makefile: Remove libqemustub.a Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 40/50] Convert remaining single line fprintf() to warn_report() Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 41/50] i386/cpu/hyperv: support over 64 vcpus for windows guests Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 42/50] hyperv: add header with protocol definitions Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 43/50] update-linux-headers: prepare for hyperv.h removal Paolo Bonzini
2017-09-19 12:36   ` Roman Kagan
2017-09-19 12:45     ` Paolo Bonzini
2017-09-19 12:29 ` Paolo Bonzini [this message]
2017-10-03 22:07   ` [Qemu-devel] [PULL 44/50] scripts: let checkpatch.pl process an entire GIT branch Alex Williamson
2017-10-04  8:33     ` Daniel P. Berrange
2017-10-04 13:17       ` Alex Williamson
2017-10-04 14:11         ` Paolo Bonzini
2017-10-04 14:20           ` Daniel P. Berrange
2017-10-04 16:16           ` Alex Williamson
2017-09-19 12:29 ` [Qemu-devel] [PULL 45/50] target/i386: fix "info mem" for LA57 mode Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 46/50] accel/hax: move hax-stub.c to accel/stubs/ Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 47/50] checkpatch: add hwaddr to @typeList Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 48/50] osdep.h: Prohibit disabling assert() in supported builds Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 49/50] default-configs: Replace $(and ...) with $(call land, ...) Paolo Bonzini
2017-09-19 12:29 ` [Qemu-devel] [PULL 50/50] docker: fix creation of archives Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505824179-21541-45-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).