diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 19:17:02 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 19:17:02 +0000 |
commit | b39aa33f12d5a500b2947a08ccc45351d530651d (patch) | |
tree | 1cf64213b8205f80dc909bed764164ac88aa2084 | |
parent | b82ff7e8291ac0e4cb4235b2ca27c141549974f3 (diff) | |
download | chromium_src-b39aa33f12d5a500b2947a08ccc45351d530651d.zip chromium_src-b39aa33f12d5a500b2947a08ccc45351d530651d.tar.gz chromium_src-b39aa33f12d5a500b2947a08ccc45351d530651d.tar.bz2 |
Check in a quick git-specific hack for doing mass renames.
Review URL: http://codereview.chromium.org/3440022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60323 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | tools/git/mass-rename.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/git/mass-rename.sh b/tools/git/mass-rename.sh new file mode 100755 index 0000000..9b6cec3 --- /dev/null +++ b/tools/git/mass-rename.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# mass-rename: update source files (gyp lists, #includes) to reflect +# a rename. Expects "git diff --cached -M" to list a bunch of renames. +# +# To use: +# 1) git mv foo1 bar1; git mv foo2 bar2; etc. +# 2) *without committing*, ./tools/git/mass-rename.sh +# 3) look at git diff (without --cached) to see what the damage is + +# rename: +# update all uses of |from| (first argument) to |to| (second argument). +rename() { + from="$1" + to="$2" + + # Fix references to the files in headers/gyp files. + echo "Processing: $from -> $to" + git grep -l "$from" -- '*.cc' '*.h' '*.m' '*.mm' '*.gyp*' | \ + xargs sed -i -e "s|$from|$to|" + + # Fix header guards. + if [ "${from##*.}" = "h" ]; then + hfrom=$(echo "$from" | tr 'a-z/' 'A-Z_' | sed -e 's|\..*$||') + hto=$(echo "$to" | tr 'a-z/' 'A-Z_' | sed -e 's|\..*$||') + echo "Processing: $hfrom -> $hto" + git grep -l "$hfrom" -- '*.cc' '*.h' '*.m' '*.mm' | \ + xargs sed -i -e "s|$hfrom|$hto|" + fi + + # Try again, stripping the first directory component -- helps with + # gyp files that rely on paths from the directory they're in. + from=$(echo "$from" | sed -e 's|^[^/]*/||') + to=$(echo "$to" | sed -e 's|^[^/]*/||') + echo "Processing: $from -> $to" + git grep -l "$from" -- '*.cc' '*.h' '*.m' '*.mm' '*.gyp*' | \ + xargs sed -i -e "s|$from|$to|" +} + +# Make the 'read' used in the while loop split only on tabs/newlines. +IFS=$'\t\n' + +git diff --cached --raw -M | while read attrs from to; do + type=$(echo "$attrs" | cut -d' ' -f5) + if echo "$type" | grep -q "^R"; then + # It's a rename. + rename "$from" "$to" + else + echo "Skipping: $from -- not a rename?" + fi +done + |