#!/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 () { $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} <>"; } print "# Added/removed/changed files:\n"; system "hg $diff | diffstat -p1 -c"; 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 = ; 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