Un-perl commit-msg hook
To simplify installation on mingw a bit (even though git remains a pain), drop the perl dependency the commit-msg hook introduced to the coreboot development environment. It's replaced by awk which we use elsewhere already (and is a more lightweight utility in any case) Change-Id: I67adfe1ec43c898735d4bae4819ceb53e83c303b Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/78 Tested-by: build bot (Jenkins) Reviewed-by: Peter Stuge <peter@stuge.se>
This commit is contained in:
		
				
					committed by
					
						
						Peter Stuge
					
				
			
			
				
	
			
			
			
						parent
						
							eb84f6a978
						
					
				
				
					commit
					ad6331d25f
				
			@@ -1,5 +1,4 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
# From Gerrit Code Review 2.1.7-rc2
 | 
					 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
 | 
					# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
@@ -37,56 +36,110 @@ add_ChangeId() {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Does Change-Id: already exist? if so, exit (no change).
 | 
				
			||||||
	if grep -i '^Change-Id:' "$MSG" >/dev/null
 | 
						if grep -i '^Change-Id:' "$MSG" >/dev/null
 | 
				
			||||||
	then
 | 
						then
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	id=`_gen_ChangeId`
 | 
						id=`_gen_ChangeId`
 | 
				
			||||||
	perl -e '
 | 
						T="$MSG.tmp.$$"
 | 
				
			||||||
		$MSG = shift;
 | 
						AWK=awk
 | 
				
			||||||
		$id = shift;
 | 
						if [ -x /usr/xpg4/bin/awk ]; then
 | 
				
			||||||
		$CHANGE_ID_AFTER = shift;
 | 
							# Solaris AWK is just too broken
 | 
				
			||||||
 | 
							AWK=/usr/xpg4/bin/awk
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
						$AWK '
 | 
				
			||||||
 | 
						# Skip lines starting with "#" without any spaces before it.
 | 
				
			||||||
 | 
						/^#/ { next }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		undef $/;
 | 
						# Skip the line starting with the diff command and everything after it,
 | 
				
			||||||
		open(I, $MSG); $_ = <I>; close I;
 | 
						# up to the end of the file, assuming it is only patch data.
 | 
				
			||||||
		s|^diff --git a/.*||ms;
 | 
						# If more than one line before the diff was empty, strip all but one.
 | 
				
			||||||
		s|^#.*$||mg;
 | 
						/^diff --git a/ {
 | 
				
			||||||
		exit unless $_;
 | 
							if (blankLines > 1) {
 | 
				
			||||||
 | 
								blankLines = 1
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							while (getline) { }
 | 
				
			||||||
 | 
							next
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		@message = split /\n/;
 | 
						# Handle comments and continuations in tags ([foo: bar] etc)
 | 
				
			||||||
		$haveFooter = 0;
 | 
						(caught == 1) && /^[ []/ {
 | 
				
			||||||
		$startFooter = @message;
 | 
							if (lines != "") {
 | 
				
			||||||
		for($line = @message - 1; $line >= 0; $line--) {
 | 
								lines = lines "\n"
 | 
				
			||||||
			$_ = $message[$line];
 | 
							}
 | 
				
			||||||
 | 
							lines = lines $0
 | 
				
			||||||
 | 
							next
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) {
 | 
						# Handle normal lines (ie. not starting with some tag like "Signed-off-by:").
 | 
				
			||||||
				$haveFooter++;
 | 
						# If normal text appears after tags were "caught", handle them as normal text, too.
 | 
				
			||||||
				next;
 | 
						# Also count blank lines in blankLines.
 | 
				
			||||||
 | 
						!/^[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\// {
 | 
				
			||||||
 | 
							if ($0 == "") {
 | 
				
			||||||
 | 
								blankLines++
 | 
				
			||||||
 | 
								next
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								for (i = 0; i < blankLines; i++) {
 | 
				
			||||||
 | 
									print ""
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			next if /^[ []/;
 | 
								blankLines = 0
 | 
				
			||||||
			$startFooter = $line if ($haveFooter && /^\r?$/);
 | 
					 | 
				
			||||||
			last;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (caught == 1) {
 | 
				
			||||||
		@footer = @message[$startFooter+1..@message];
 | 
								caught = 0
 | 
				
			||||||
		@message = @message[0..$startFooter];
 | 
								print lines
 | 
				
			||||||
		push(@footer, "") unless @footer;
 | 
								lines = ""
 | 
				
			||||||
 | 
					 | 
				
			||||||
		for ($line = 0; $line < @footer; $line++) {
 | 
					 | 
				
			||||||
			$_ = $footer[$line];
 | 
					 | 
				
			||||||
			next if /^($CHANGE_ID_AFTER):/i;
 | 
					 | 
				
			||||||
			last;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		splice(@footer, $line, 0, "Change-Id: I$id");
 | 
							print $0
 | 
				
			||||||
 | 
							next
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$_ = join("\n", @message, @footer);
 | 
						# Handle tags.  They are "caught" and collected in the "lines" variable
 | 
				
			||||||
		open(O, ">$MSG"); print O; close O;
 | 
						{
 | 
				
			||||||
	' "$MSG" "$id" "$CHANGE_ID_AFTER"
 | 
							caught = 1
 | 
				
			||||||
 | 
							if (lines != "") {
 | 
				
			||||||
 | 
								lines = lines "\n";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							lines = lines $0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Tag handling:
 | 
				
			||||||
 | 
						# If last line before tags was not blank, there were no tags.
 | 
				
			||||||
 | 
						# In that case, print everything, plus a blank line, followed by Change-Id.
 | 
				
			||||||
 | 
						# Otherwise there were tags. Look for the right place to inject Change-Id,
 | 
				
			||||||
 | 
						# by considering CHANGE_ID_AFTER. Tags listed in it (case insensitive) come first,
 | 
				
			||||||
 | 
						# then Change-Id, then everything else (eg. Signed-off-by:).
 | 
				
			||||||
 | 
						END {
 | 
				
			||||||
 | 
							unprinted = 1
 | 
				
			||||||
 | 
							if (blankLines == 0) {
 | 
				
			||||||
 | 
								if (lines == "") {
 | 
				
			||||||
 | 
									 print ""
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									print lines "\n"
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								for (i = 0; i < blankLines; i++) {
 | 
				
			||||||
 | 
									print ""
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
 | 
				
			||||||
 | 
								numlines = split(lines, footer, "\n")
 | 
				
			||||||
 | 
								for (line = 1; line <= numlines; line++) {
 | 
				
			||||||
 | 
									if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
 | 
				
			||||||
 | 
										unprinted = 0
 | 
				
			||||||
 | 
										print "Change-Id: I'"$id"'"
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									print footer[line]
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (unprinted) {
 | 
				
			||||||
 | 
								print "Change-Id: I'"$id"'"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}' "$MSG" > $T && mv $T "$MSG" || rm -f $T
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
_gen_ChangeIdInput() {
 | 
					_gen_ChangeIdInput() {
 | 
				
			||||||
	echo "tree `git write-tree`"
 | 
						echo "tree `git write-tree`"
 | 
				
			||||||
	if parent=`git rev-parse HEAD^0 2>/dev/null`
 | 
						if parent=`git rev-parse "HEAD^0" 2>/dev/null`
 | 
				
			||||||
	then
 | 
						then
 | 
				
			||||||
		echo "parent $parent"
 | 
							echo "parent $parent"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user