diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh --- a/tools/tools/git/git-arc.sh +++ b/tools/tools/git/git-arc.sh @@ -147,6 +147,8 @@ exit 1 } +# Looks up Phabricator Internal ID (PHID) for a given Revision ID. +# The input must match regex D[1-9][0-9]* (i.e D1234) diff2phid() { local diff @@ -161,6 +163,13 @@ jq -r "select(.response != []) | .response.${diff}.phid" } +# Prints status of a given Differential Revision +# The output looks like: +# closed my awseome feature +# +# TODO: improvement to avoid calling jq twice +# jq_output=$(jq -r "select(.response != []) | .response.${diff} | (.status, .fullName) | @text \"%-14s %s\"" < "$json") +printf "$jq_output\n" diff2status() { local diff tmp status summary @@ -179,6 +188,13 @@ printf "%-14s %s\n" "${status}" "${summary}" } + +# log2diff: Extract the Differential Revision identifier from the commit +# message of a given commit. +# Usage: log2diff +# Input: A Git commit hash or reference. +# Output: Echoes the extracted Differential Revision id (e.g., D1234) +# if found and unique, or an empty string otherwise. log2diff() { local diff @@ -194,6 +210,14 @@ # Look for an open revision with a title equal to the input string. Return # a possibly empty list of Differential revision IDs. +# +# title2diff: Search for the Differential Revision identifier (e.g., D1234) +# by matching the input title against the titles fetched from the +# 'arc list' command. +# Usage: title2diff +# Input: A string representing the title of a Differential Revision. +# Output: Echoes the corresponding Differential Revision identifier +# (e.g. D1234) if a matching title is found, or nothing otherwise. title2diff() { local title @@ -464,18 +488,18 @@ # freebsd.org (which isn't surprising for ports committers getting src # commits reviewed). case "${addr}" in - *.*) ;; # external user + *.*) ;; # external user *) - echo "${name} <${addr}@FreeBSD.org>" - return - ;; + echo "${name} <${addr}@FreeBSD.org>" + return + ;; esac # Choice 2: authorAddr and authorName were set somehow in the bundle, so use # that. We may need to filter some known bogus ones, should they crop up. if [ -n "$authorName" -a -n "$authorAddr" ]; then - echo "${authorName} <${authorAddr}>" - return + echo "${authorName} <${authorAddr}>" + return fi # Choice 3: We can find this user in the FreeBSD repo. They've submited @@ -483,8 +507,8 @@ # similar to their phab username. email=$(git log -1 --author "$(echo ${addr} | tr _ .)" --pretty="%aN <%aE>") if [ -n "${email}" ]; then - echo "${email}" - return + echo "${email}" + return fi # Choice 4: We know this user. They've committed before, and they happened @@ -492,11 +516,11 @@ # might not be a good idea, since names can be somewhat common (there # are two Andrew Turners that have contributed to FreeBSD, for example). if ! (echo "${name}" | grep -w "[Uu]ser" -q); then - email=$(git log -1 --author "${name}" --pretty="%aN <%aE>") - if [ -n "$email" ]; then - echo "$email" - return - fi + email=$(git log -1 --author "${name}" --pretty="%aN <%aE>") + if [ -n "$email" ]; then + echo "$email" + return + fi fi # Choice 5: Wing it as best we can. In this scenario, we replace the last _ @@ -523,13 +547,13 @@ # Get the author phid for this patch review_data=$(echo '{ "constraints": {"phids": ["'"$reviewid"'"]} - }' | + }' | arc_call_conduit -- differential.revision.search) authorid=$(echo "$review_data" | jq -r '.response.data[].fields.authorPHID' ) # Get metadata about the user that submitted this patch user_data=$(echo '{ "constraints": {"phids": ["'"$authorid"'"]} - }' | + }' | arc call-conduit -- user.search | grep -v ^Warning: | jq -r '.response.data[].fields') user_addr=$(echo "$user_data" | jq -r '.username') @@ -541,17 +565,17 @@ # remove duplicates 'just to be sure' since we've not seen multiple # records that match. diff_data=$(echo '{ - "revisionIDs": [ '"${diff#D}"' ] - }' | arc_call_conduit -- differential.querydiffs | - jq -r '.response | flatten | .[]') + "revisionIDs": [ '"${diff#D}"' ] + }' | arc_call_conduit -- differential.querydiffs | + jq -r '.response | flatten | .[]') author_addr=$(echo "$diff_data" | jq -r ".authorEmail" | grep -v null | sort -u) author_name=$(echo "$diff_data" | jq -r ".authorName" | grep -v null | sort -u) author=$(find_author "$user_addr" "$user_name" "$author_addr" "$author_name") # If we had to guess, and the user didn't want to guess, abort if [ "${author}" = "ABORT" ]; then - warn "Not committing due to uncertainty over author name" - exit 1 + warn "Not committing due to uncertainty over author name" + exit 1 fi tmp=$(mktemp) @@ -581,7 +605,7 @@ while getopts c o; do case "$o" in c) - require_clean_work_tree "patch -c" + require_clean_work_tree "patch -c" commit=true ;; *) @@ -595,9 +619,9 @@ arc patch --skip-dependencies --nocommit --nobranch --force "$rev" echo "Applying ${rev}..." [ $? -eq 0 ] || break - if $commit; then - patch_commit $rev - fi + if $commit; then + patch_commit $rev + fi done }