From 8ce79af03f04b59f1dc2b2cada5230255211d963 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 11:18:54 +0000 Subject: [PATCH 1/7] Adding draft tool script for assessing the risk of changes to the MPS. --- tool/git-riskiness | 293 +++++++++++++++++++++++++++++++++++++++++++++ tool/git-risks | 37 ++++++ 2 files changed, 330 insertions(+) create mode 100644 tool/git-riskiness create mode 100755 tool/git-risks diff --git a/tool/git-riskiness b/tool/git-riskiness new file mode 100644 index 0000000000..8ab6950af2 --- /dev/null +++ b/tool/git-riskiness @@ -0,0 +1,293 @@ +# -*- mode: conf-space; -*- +# tool/git-riskiness -- estimate of risks of changing files in the MPS tree +# +# This file is used by the script tool/git-risks to assess the +# riskiness of changes made to the MPS. [Insert why it was developed, +# ref to issue, etc. RB 2023-02-24] +# +# First draft by manual inspection by RB and JPH on 2023-02-20. +# +# This file can contain blank lines and comments starting with '#'. +# See tool/git-risks. + +0 0 code/.gitignore +0 0 code/.p4ignore +1 0 code/abq.c +1 0 code/abq.h +0 0 code/abqtest.c +0 0 code/airtest.c +0 0 code/amcss.c +0 0 code/amcsshe.c +0 0 code/amcssth.c +0 0 code/amsss.c +0 0 code/amssshe.c +0 0 code/anangc.gmk +0 0 code/ananll.gmk +0 0 code/ananmv.nmk +0 0 code/apss.c +2 2 code/arena.c +2 0 code/arenacl.c +0 0 code/arenacv.c +2 2 code/arenavm.c +1 1 code/arg.c +1 1 code/arg.h +0 0 code/awlut.c +0 0 code/awluthe.c +0 0 code/awlutth.c +1 1 code/boot.c +1 1 code/boot.h +3 3 code/bt.c +3 3 code/bt.h +0 0 code/btcv.c +0 0 code/bttest.c +4 4 code/buffer.c +3 3 code/cbs.c +3 3 code/cbs.h +? ? chain.h extra file +3 3 code/check.h +1 0 code/clock.h +0 0 code/comm.gmk +0 0 code/commpost.nmk +0 0 code/commpre.nmk +1 1 code/config.h +2 0 code/dbgpool.c +2 0 code/dbgpool.h +2 0 code/dbgpooli.c +0 0 code/djbench.c +1 0 code/event.c +1 0 code/event.h +0 0 code/eventcnv.c +1 0 code/eventcom.h +1 0 code/eventdef.h +0 0 code/eventpy.c +0 0 code/eventsql.c +0 0 code/eventtxt.c +3 3 code/failover.c +3 3 code/failover.h +0 0 code/finalcv.c +0 0 code/finaltest.c +0 0 code/fmtdy.c +0 0 code/fmtdy.h +0 0 code/fmtdytst.c +0 0 code/fmtdytst.h +0 0 code/fmthe.c +0 0 code/fmthe.h +0 0 code/fmtno.c +0 0 code/fmtno.h +0 0 code/fmtscheme.c +0 0 code/fmtscheme.h +0 0 code/forktest.c +2 2 code/format.c +0 0 code/fotest.c +3 3 code/freelist.c +3 3 code/freelist.h +0 0 code/fri3gc.gmk +0 0 code/fri3ll.gmk +0 0 code/fri6gc.gmk +0 0 code/fri6ll.gmk +0 0 code/gc.gmk +0 0 code/gcbench.c +0 0 code/gcovfmt.py +0 0 code/getopt.h +0 0 code/getoptl.c +2 2 code/global.c +0 0 code/gp.gmk +3 3 code/land.c +0 0 code/landtest.c +4 4 code/ld.c +0 0 code/lia6gc.gmk +0 0 code/lia6ll.gmk +0 0 code/lii3gc.gmk +0 0 code/lii6gc.gmk +0 0 code/lii6ll.gmk +0 0 code/ll.gmk +0 0 code/locbwcss.c +1 1 code/lock.h +1 0 code/lockan.c +0 0 code/lockcov.c +2 0 code/lockix.c +0 0 code/lockut.c +0 0 code/lockutw3.c +2 2 code/lockw3.c +3 3 code/locus.c +3 3 code/locus.h +0 0 code/locusss.c +0 0 code/locv.c +1 1 code/message.c +0 0 code/messtest.c +1 1 code/meter.c +1 1 code/meter.h +3 3 code/misc.h +2 2 code/mpm.c +2 2 code/mpm.h +0 0 code/mpmss.c +2 2 code/mpmst.h +2 2 code/mpmtypes.h +1 1 code/mps.c +3 3 code/mps.h +0 0 code/mps.xcodeproj/project.pbxproj +2 0 code/mpsacl.h +2 2 code/mpsavm.h +1 1 code/mpscamc.h +1 0 code/mpscams.h +1 1 code/mpscawl.h +1 0 code/mpsclo.h +1 0 code/mpscmfs.h +1 0 code/mpscmv2.h +1 0 code/mpscmvff.h +1 0 code/mpscmvt.h +1 0 code/mpscsnc.h +2 2 code/mpsi.c +0 0 code/mpsicv.c +1 1 code/mpsio.h +1 1 code/mpsioan.c +2 2 code/mpsiw3.c +1 1 code/mpslib.h +1 1 code/mpsliban.c +1 1 code/mpstd.h +1 1 code/mpswin.h +0 0 code/mv.nmk +0 0 code/mv2test.c +3 3 code/nailboard.c +3 3 code/nailboard.h +0 0 code/nailboardtest.c +0 0 code/pc.nmk +3 3 code/policy.c +2 2 code/pool.c +1 1 code/poolabs.c +3 3 code/poolamc.c +3 0 code/poolams.c +1 0 code/poolams.h +3 3 code/poolawl.c +3 0 code/poollo.c +3 3 code/poolmfs.c +1 1 code/poolmfs.h +3 3 code/poolmrg.c +1 1 code/poolmrg.h +3 0 code/poolmv2.c +1 0 code/poolmv2.h +3 3 code/poolmvff.c +1 1 code/poolmvff.h +0 0 code/pooln.c +0 0 code/pooln.h +0 0 code/poolncv.c +3 0 code/poolsnc.c +3 3 code/prmc.h +3 0 code/prmcan.c +3 0 code/prmcanan.c +3 0 code/prmcfri3.c +3 0 code/prmcfri6.c +3 0 code/prmci3.c +3 0 code/prmci3.h +3 0 code/prmci3fr.c +3 0 code/prmci3li.c +3 0 code/prmci3w3.c +3 0 code/prmci3xc.c +3 3 code/prmci6.c +3 3 code/prmci6.h +3 0 code/prmci6fr.c +3 0 code/prmci6li.c +3 3 code/prmci6w3.c +3 0 code/prmci6xc.c +3 0 code/prmcix.c +3 0 code/prmcix.h +3 0 code/prmclia6.c +3 0 code/prmclii3.c +3 0 code/prmclii6.c +3 3 code/prmcw3.c +3 3 code/prmcw3.h +3 0 code/prmcw3i3.c +3 3 code/prmcw3i6.c +3 0 code/prmcxc.c +3 0 code/prmcxc.h +3 0 code/prmcxca6.c +3 0 code/prmcxci3.c +3 0 code/prmcxci6.c +1 1 code/prot.h +1 0 code/protan.c +2 0 code/proti3.c +2 2 code/proti6.c +2 0 code/protix.c +2 2 code/protocol.c +2 2 code/protocol.h +3 0 code/protsgix.c +3 3 code/protw3.c +3 0 code/protxc.c +3 0 code/protxc.h +2 0 code/pthrdext.c +2 0 code/pthrdext.h +0 0 code/qs.c +2 2 code/range.c +2 2 code/range.h +2 2 code/rangetree.c +2 2 code/rangetree.h +3 3 code/ref.c +2 2 code/ring.c +2 2 code/ring.h +3 3 code/root.c +3 3 code/sa.c +3 3 code/sa.h +2 0 code/sac.c +2 0 code/sac.h +0 0 code/sacss.c +4 4 code/scan.c +3 3 code/seg.c +0 0 code/segsmss.c +4 4 code/shield.c +0 0 code/sncss.c +1 1 code/sp.h +3 0 code/span.c +? ? spi3.c +3 3 code/splay.c +1 1 code/splay.h +3 0 code/spw3i3.c +3 3 code/spw3i6.c +3 3 code/ss.c +3 3 code/ss.h +0 0 code/steptest.c +2 2 code/table.c +1 1 code/table.h +0 0 code/tagtest.c +0 0 code/teletest.c +0 0 code/testlib.c +0 0 code/testlib.h +0 0 code/testthr.h +0 0 code/testthrix.c +0 0 code/testthrw3.c +1 1 code/th.h +1 0 code/than.c +2 0 code/thix.c +2 2 code/thw3.c +2 0 code/thxc.c +4 4 code/trace.c +3 3 code/traceanc.c +2 2 code/tract.c +2 2 code/tract.h +2 2 code/tree.c +1 1 code/tree.h +1 1 code/version.c +1 1 code/vm.c +1 1 code/vm.h +1 1 code/vman.c +2 2 code/vmix.c +2 2 code/vmw3.c +0 0 code/w3i3mv.nmk +0 0 code/w3i3pc.nmk +0 0 code/w3i6mv.bat +0 0 code/w3i6mv.nmk +0 0 code/w3i6pc.nmk +0 0 code/w3mv/.gitignore +0 0 code/w3mv/.p4ignore +0 0 code/w3mv/amcss/amcss.vcxproj +0 0 code/w3mv/eventcnv/eventcnv.vcxproj +0 0 code/w3mv/mps.sln +0 0 code/w3mv/mps/mps.vcxproj +3 3 code/walk.c +0 0 code/walkt0.c +0 0 code/xca6ll.gmk +0 0 code/xci3gc.gmk +0 0 code/xci3ll.gmk +0 0 code/xci6gc.gmk +0 0 code/xci6ll.gmk +0 0 code/zcoll.c +0 0 code/zmess.c diff --git a/tool/git-risks b/tool/git-risks new file mode 100755 index 0000000000..46a003a103 --- /dev/null +++ b/tool/git-risks @@ -0,0 +1,37 @@ +#!/bin/bash +# Estimate the risk of changes to the MPS. +# +# [Insert why this was developed, ref to issue, etc. RB 2023-02-24] +# +# Takes arguments to ``git log``. For example, to assess changes on +# master:: +# +# tool/git-risks --first-parent -n 10 master +# +# The estimate of the risks of changing files is stored in +# tool/git-riskiness +# +# TODO: Take option to select risk column argument to sort. +# +# Developed from . + +git log --format="%H %h %s" "$@" | +while read -r hash commit subject; do + risks=$( + # Strip comments and blank lines from git-riskiness + sed --regexp-extended \ + --expression='s/[[:space:]]*#.*$//; /^[[:space:]]*$/ d' < tool/git-riskiness | + # Filter lines that mention files changed in the commit + ( + grep --fixed-strings \ + --file=<(git log --max-count=1 --patch \ + --diff-merges=on --name-only \ + --pretty="format:" "$hash") || + echo "0 0 no-match" + ) | + # Pick the riskiest + sort --numeric --reverse --key=1 | + head --lines=1 + ) + echo "$commit $risks $subject" +done From 68d828280e44fef3f7b910a7408fe26b1e7a72d8 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 20:31:00 +0000 Subject: [PATCH 2/7] Clarifying what the columns are for. --- tool/git-riskiness | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tool/git-riskiness b/tool/git-riskiness index 8ab6950af2..36174e6924 100644 --- a/tool/git-riskiness +++ b/tool/git-riskiness @@ -10,6 +10,8 @@ # This file can contain blank lines and comments starting with '#'. # See tool/git-risks. +# First column is risk to general MPS users +# Second column is risk to Configura 0 0 code/.gitignore 0 0 code/.p4ignore 1 0 code/abq.c From 511760fdbdbf8569cf66e3b2e0351622b4c8b3cc Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 20:31:30 +0000 Subject: [PATCH 3/7] For the purpose of risk, ignoring lines that look like comments. --- tool/git-risks | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/tool/git-risks b/tool/git-risks index 46a003a103..e06de1251b 100755 --- a/tool/git-risks +++ b/tool/git-risks @@ -18,20 +18,27 @@ git log --format="%H %h %s" "$@" | while read -r hash commit subject; do risks=$( - # Strip comments and blank lines from git-riskiness + # Strip comments and blank lines from git-riskiness. sed --regexp-extended \ --expression='s/[[:space:]]*#.*$//; /^[[:space:]]*$/ d' < tool/git-riskiness | - # Filter lines that mention files changed in the commit - ( - grep --fixed-strings \ - --file=<(git log --max-count=1 --patch \ - --diff-merges=on --name-only \ - --pretty="format:" "$hash") || - echo "0 0 no-match" - ) | - # Pick the riskiest - sort --numeric --reverse --key=1 | - head --lines=1 - ) - echo "$commit $risks $subject" + # Filter for lines that mention files changed in the commit. + # Ignores lines that look like comments. + ( + grep --fixed-strings \ + --file=<(git show --pretty="format:" \ + --patch \ + --diff-merges=first-parent \ + --ignore-matching-lines='^[[:space:]]+\*[[:space:]]' \ + --ignore-matching-lines='^[[:space:]]*/\*[[:space:]]' \ + --ignore-space-change \ + "$hash" | + sed --quiet --expression='s!--- a/!!p') || + echo "0 0 no-match" + ) | + # Pick the riskiest. + # NOTE: --key is 1-based. + sort --numeric --reverse --key=2 | + head --lines=1 + ) + echo "$commit $loc $risks $subject" done From 39ed92fb6ea93d05c348cb182fe062bc8b174313 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 20:59:52 +0000 Subject: [PATCH 4/7] Output a count of non-comment lines changed. Remove bashism. --- tool/git-risks | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tool/git-risks b/tool/git-risks index e06de1251b..08ae2eba52 100755 --- a/tool/git-risks +++ b/tool/git-risks @@ -15,24 +15,35 @@ # # Developed from . +if difftmp=$(mktemp); then + trap "rm -f -- '$difftmp'" EXIT +else + echo 1>&2 "Unable to create temporary file" + exit 1 +fi + git log --format="%H %h %s" "$@" | while read -r hash commit subject; do + # Get a diff for the change. Ignoring lines that look like + # comments, or with just white space changes. This is hacky + # because it only recognizes C comments. + git show --pretty="format:" --patch \ + --diff-merges=first-parent \ + --ignore-matching-lines='^[[:space:]]+\*[[:space:]]' \ + --ignore-matching-lines='^[[:space:]]*/\*[[:space:]]' \ + --ignore-space-change \ + "$hash" > $difftmp + loc=$(wc -l < "$difftmp") + # Edit diff to just a list of files changed + sed --in-place --quiet --expression='s!--- a/!!p' "$difftmp" risks=$( # Strip comments and blank lines from git-riskiness. sed --regexp-extended \ - --expression='s/[[:space:]]*#.*$//; /^[[:space:]]*$/ d' < tool/git-riskiness | + --expression='s/[[:space:]]*#.*$//; /^[[:space:]]*$/ d' \ + < tool/git-riskiness | # Filter for lines that mention files changed in the commit. - # Ignores lines that look like comments. ( - grep --fixed-strings \ - --file=<(git show --pretty="format:" \ - --patch \ - --diff-merges=first-parent \ - --ignore-matching-lines='^[[:space:]]+\*[[:space:]]' \ - --ignore-matching-lines='^[[:space:]]*/\*[[:space:]]' \ - --ignore-space-change \ - "$hash" | - sed --quiet --expression='s!--- a/!!p') || + grep --fixed-strings --file="$difftmp" || echo "0 0 no-match" ) | # Pick the riskiest. @@ -40,5 +51,5 @@ while read -r hash commit subject; do sort --numeric --reverse --key=2 | head --lines=1 ) - echo "$commit $loc $risks $subject" + echo "$commit $risks $loc $subject" done From 4b1265a5877db19398dd384800ad890118bbe16e Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 21:09:04 +0000 Subject: [PATCH 5/7] Improving output formatting. Fixing shellcheck warnings. --- tool/git-risks | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tool/git-risks b/tool/git-risks index 08ae2eba52..86a8770ac0 100755 --- a/tool/git-risks +++ b/tool/git-risks @@ -16,6 +16,7 @@ # Developed from . if difftmp=$(mktemp); then + # shellcheck disable=SC2064 trap "rm -f -- '$difftmp'" EXIT else echo 1>&2 "Unable to create temporary file" @@ -32,7 +33,7 @@ while read -r hash commit subject; do --ignore-matching-lines='^[[:space:]]+\*[[:space:]]' \ --ignore-matching-lines='^[[:space:]]*/\*[[:space:]]' \ --ignore-space-change \ - "$hash" > $difftmp + "$hash" > "$difftmp" loc=$(wc -l < "$difftmp") # Edit diff to just a list of files changed sed --in-place --quiet --expression='s!--- a/!!p' "$difftmp" @@ -51,5 +52,5 @@ while read -r hash commit subject; do sort --numeric --reverse --key=2 | head --lines=1 ) - echo "$commit $risks $loc $subject" + printf "%s %5d %s %s\n" "$commit" "$loc" "$risks" "$subject" done From 3334f1a1dc379eff1ce1cba6d6945f6e1fd0d293 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 24 Feb 2023 21:48:43 +0000 Subject: [PATCH 6/7] Adding option to select risk column. --- tool/git-risks | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tool/git-risks b/tool/git-risks index 86a8770ac0..d683632aec 100755 --- a/tool/git-risks +++ b/tool/git-risks @@ -11,10 +11,23 @@ # The estimate of the risks of changing files is stored in # tool/git-riskiness # -# TODO: Take option to select risk column argument to sort. -# # Developed from . +usage() { + echo 1>&2 "Usage: ${0} [-k column] [-- git log options] [...]" + exit 1 +} + +# Default to general risk (column 1 in git-riskiness) +key=1 +while getopts k: flag; do + case "${flag}" in + k) key="${OPTARG}";; + *) usage;; + esac +done +shift $((OPTIND-1)) + if difftmp=$(mktemp); then # shellcheck disable=SC2064 trap "rm -f -- '$difftmp'" EXIT @@ -49,7 +62,7 @@ while read -r hash commit subject; do ) | # Pick the riskiest. # NOTE: --key is 1-based. - sort --numeric --reverse --key=2 | + sort --numeric --reverse --key="$key" | head --lines=1 ) printf "%s %5d %s %s\n" "$commit" "$loc" "$risks" "$subject" From 35b7281c5b4fea14fe3f4841b348afc99fe67bc3 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Sat, 25 Feb 2023 07:46:42 +0000 Subject: [PATCH 7/7] Adding draft tool script to show C functions changed between commits. --- tool/git-fundiff | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 tool/git-fundiff diff --git a/tool/git-fundiff b/tool/git-fundiff new file mode 100755 index 0000000000..7008980080 --- /dev/null +++ b/tool/git-fundiff @@ -0,0 +1,50 @@ +#!/bin/sh +# tool/git-fundiff -- C functions changed between commits +# +# Prints a list of functions that differ in a C source file at the +# LLVM intermediate code level between two Git commits. +# +# NOTE: This will print false positivies because llvm-diff produces +# them, even when comparing a file with itself, e.g. ``llvm-diff x x`` + +set -e # exit on error + +usage() { + echo 1>&2 "Usage: $0 ..." + echo 1>&2 "Example: $0 HEAD^ HEAD trace.c" + exit 2 +} + +if ! which clang llvm-diff-14 > /dev/null; then + echo 1>&2 "$0: clang or llvm-diff-14 command not found" + exit 2 +fi + +if test "$#" -lt 2; then usage; fi +left="$1" +right="$2" +shift 2 + +tmpdir=$(mktemp --directory) +# shellcheck disable=SC2064 +trap "rm -rf -- '$tmpdir'" EXIT +mkdir -p "$tmpdir/left" "$tmpdir/right" +git archive "$left" code | tar -x -C "$tmpdir/left" +git archive "$right" code | tar -x -C "$tmpdir/right" + +status=0 +while test $# -gt 0; do + file="$1" + shift + (cd "$tmpdir/left/code" && + clang -S -emit-llvm -o "../../left.ll" "$file") + (cd "$tmpdir/right/code" && + clang -S -emit-llvm -o "../../right.ll" "$file") + # Try to reduce false positives where the output is identical + cmp "$tmpdir/left.ll" "$tmpdir/right.ll" && continue + llvm-diff-14 "$tmpdir/left.ll" "$tmpdir/right.ll" \ + > "$tmpdir/diff" 2>&1 && continue + status=1 + sed -ne 's/^in function \(.*\):$/\1/p' < "$tmpdir/diff" +done +exit "$status"