summaryrefslogtreecommitdiff
path: root/v4l/scripts/prep_commit_msg.pl
blob: 1316a7c44faf8ede62c8cba545a7789bdee62b98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl

my $diff = 'diff';
if ($ARGV[0] eq '-q') {
    $diff = 'qdiff';
    shift;
}
my $autopatch = shift;

# Get Hg username from environment
my $user = $ENV{HGUSER};

sub hgrcuser($)
{
	my $file = shift;
	my $ui = 0;
	open IN, '<', $file;
	while (<IN>) {
		$ui = 1 if (/^\s*\[ui\]/);
		if ($ui && /^\s*username\s*=\s*(\S.*?)\s*$/) {
			close IN;
			return($1);
		}
	}
	close IN;
	return("");
}

# Didn't work? Try the repo's .hgrc file
if ($user eq "") {
	my $hgroot = `hg root`;
	chomp($hgroot);
	$user = hgrcuser("$hgroot/.hg/hgrc");
}
# Ok, try ~/.hgrc next
if ($user eq "") {
	$user = hgrcuser("$ENV{HOME}/.hgrc");
}

# Still no luck? Try some other environment variables
if ($user eq "") {
	my $name = $ENV{CHANGE_LOG_NAME};
	my $email = $ENV{CHANGE_LOG_EMAIL_ADDRESS};
	$user = "$name <$email>" if ($name ne "" || $email ne "");
}

# Last try to come up with something
if ($user eq "") {
	$user = "$ENV{USER} <>";
}

$checkpatch=$ENV{CHECKPATCH};

if (!$checkpatch) {
	$checkpatch="/lib/modules/`uname -r`/build/scripts/checkpatch.pl";
}

print "# Added/removed/changed files:\n";
system "hg $diff | diffstat -p1 -c";

open IN,"hg $diff | $checkpatch -q --nosignoff --notree -|";
my $err=0;
while (<IN>) {
	if (!$err) {
		print "#\n# WARN: checkpatch.pl returned some errors. Please fix.\n";
		$err=1;
	}
	print "# $_";
}
close IN;


if (-s $autopatch) {
	print "#\n# Note, a problem with your patch was detected!  These changes were made\n";
	print "# automatically: $autopatch\n";
	system "diffstat -p0 -c $autopatch";
	print "#\n# Please review these changes and see if they belong in your patch or not.\n";
}
if ($diff eq 'qdiff') {
	# Use existing mq patch logfile?
	open IN, "hg qheader |";
	my @header = <IN>;
	close IN;

	if ($#header > 0) {
		# Use existing header
		print @header;
		exit;
	}
	# No header, use pre-made log message below

	# Hg will strip lines that start with "From: " from mq patch headers!
	# In order to stop it, we insert this extra From line at the top,
	# Hg will strip it and then leave the real from line alone.
	print "From: $user\n\n";
}
print <<"EOF";
#
# For better log display, please keep a blank line after subject, after from,
# and before signed-off-by.
# First line should be the subject, without Subject:
#


# Now, patch author (just the main one), on a From: field
# Please change below if the committer is not the patch author.
#
From: $user

# Then a detailed description:


# At the end Signed-off-by: fields by patch author and committer, at least.
#
Signed-off-by: $user
EOF