[coreboot-gerrit] Change in coreboot[master]: util/scripts/gerrit-rebase: allow skipping old history

Patrick Georgi (Code Review) gerrit at coreboot.org
Tue Jun 13 15:19:05 CEST 2017


Patrick Georgi has uploaded this change for review. ( https://review.coreboot.org/20185


Change subject: util/scripts/gerrit-rebase: allow skipping old history
......................................................................

util/scripts/gerrit-rebase: allow skipping old history

This might provide a minor speedup but more importantly it allows
skipping commits without Reviewed-on line (which we have a couple of
due to mistakes with git push).

To use, add a line starting with "Gerrit-Rebase-Ignore-CLs-Before:"
pointing out a match string (ie "something that comes after Reviewed-on")
prior to which no changes are considered on the originating branch. The
target branch is still fully considered to avoid issues with changes
that were retargetted out of order around the new cut and would then
make a reappearance (or be skipped).

Change-Id: I9f2679891e93f6d28a781315aebd2aa60a1e3b23
Signed-off-by: Patrick Georgi <pgeorgi at google.com>
---
M util/scripts/gerrit-rebase
1 file changed, 32 insertions(+), 4 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/85/20185/1

diff --git a/util/scripts/gerrit-rebase b/util/scripts/gerrit-rebase
index 8f59e7f..c4f8a80 100755
--- a/util/scripts/gerrit-rebase
+++ b/util/scripts/gerrit-rebase
@@ -27,7 +27,22 @@
 # so go for Reviewed-on instead. It's also unique because it
 # contains the gerrit instance's host name and the change's number
 # on that system.
-match_string='^    [-A-Za-z]*[Rr]eviewed-on: '
+match_string='[-A-Za-z]*[Rr]eviewed-on:'
+
+# Custom root: allow a certain CL (identified by matching either side's
+# match_string) to be the new root, instead of using git's common history only.
+# This allows cutting down on commits that are re-evaluated on every run.
+#
+# Use:
+# To the commit message of a commit on the "to" side, add
+# $custom_root: match_string (the part coming after $match_string)
+#
+# For a $match_string of ~ "Reviewed-on: " this might
+# be "$custom_root: https://example.com/12345"
+#
+# On traversal, the commit with "$match_string: https://example.com/12345"
+# is then considered a base commit.
+custom_root='^Gerrit-Rebase-Ignore-CLs-Before:'
 
 # fetch common ancestor
 common_base=$(git merge-base ${from} ${to} 2>/dev/null)
@@ -37,9 +52,22 @@
 	exit 1
 fi
 
+from_base=$common_base
+
+# fetch custom root ID
+croot_marker=$(git log --pretty=%b -1 --grep "${custom_root}" \
+	${common_base}..${to} | \
+	grep "${custom_root}" | cut -d: -f2-)
+if [ -n "${croot_marker}" ]; then
+	from_base=$( ( \
+		git log --pretty=%H -1 \
+		--grep "^${match_string}${croot_marker}" \
+		${from_base}..${from}; echo ${from_base} )| head -1)
+fi
+
 # collect matches that are present on the target side
 to_matches="$(git log ${common_base}..${to} | \
-	grep "${match_string}" | \
+	grep "^    ${match_string}" | \
 	cut -d: -f2-)"
 
 # start rebase process, but fail immediately by enforcing an invalid todo
@@ -49,8 +77,8 @@
 # write new rebase todo
 # the appended "commit" line triggers handling of the last log entry
 commit=""
-(git log --reverse ${common_base}..${from} | \
-	grep -E "(^commit [0-9a-f]{40}\$|${match_string})"; \
+(git log --reverse ${from_base}..${from} | \
+	grep -E "(^commit [0-9a-f]{40}\$|^    ${match_string})"; \
 	echo "commit") | \
 while read key value; do
 	if [ "${key}" = "commit" ]; then

-- 
To view, visit https://review.coreboot.org/20185
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f2679891e93f6d28a781315aebd2aa60a1e3b23
Gerrit-Change-Number: 20185
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Georgi <pgeorgi at google.com>



More information about the coreboot-gerrit mailing list