Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F29463400
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
thcipriani
Jun 11 2019, 7:27 PM
2019-06-11 19:27:00 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
#!/usr/bin/env bash
#
# Gerrit Username To Lowercase
# =====================
#
# Script for converting gerrit:-scheme usernames to lowercase directly
# in a checkout of refs/meta/external-ids of the All-Users git repo.
#
# Copyright: Tyler Cipriani <tcipriani@wikimedia.org> 2019
# License: GPLv3+
# Utility logging methods
info() {
printf '[INFO] %s' "$@"
}
println() {
printf '%s\n' "$@"
}
# Convert username with gerrit: schema to lowercase
#
# accepts a username as a mixed case string without a schema by:
#
# 1. Convert username mixed case to username lowercase
# 2. Compute sha1sum of lowercase schema for use as new file name
# 3. Find the old file name using git grep
# 4. Git move the old file to the new file path (computed with sha1sum)
# 5. Replace the username mixed-case in the new file with username lowercase
#
# param username: string, mixed case
usernameToLower() {
local username username_lower shasum new_file old_file
username="$1"
username_lower="${username,,}"
shasum=$(printf "gerrit:%s" "${username_lower}" | shasum -a 1)
new_file=$(printf '%s/%s\n' "${shasum:0:2}" "${shasum:2:38}")
old_file=$(git grep --full-name --files-with-matches "\"gerrit:${username}\"")
if [ -f "$new_file" ]; then
println "The new file '${new_file}' exists!!!! for '${username}'. Aborting!"
exit 1
fi
git mv "$old_file" "$new_file"
# Change username to lowercase in new file
sed -i "s/gerrit:${username}/gerrit:${username_lower}/" "$new_file"
}
# Find any gerrit:-schema users with capital letters
# Look to see if there is a lowercase version
# If not, convert user to lowercase
main() {
while read -r user; do
# Grep for lowercase user
if git grep "\\[externalId \"gerrit:${user,,}\"\\]" &>/dev/null; then
continue
fi
info "Converting ${user}..."
usernameToLower "$user"
println "DONE!"
done < <(git grep -P 'gerrit:.*[A-Z]+.*' | sed -e 's/.*:\[externalId "gerrit:\(.*\)"]/\1/')
}
main "$@"
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7616513
Default Alt Text
raw.txt (1 KB)
Attached To
Mode
P8606 gerritUsernameToLowercase.sh
Attached
Detach File
Event Timeline
Log In to Comment