OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # mass-rename: update source files (gyp lists, #includes) to reflect | 6 # mass-rename: update source files (gyp lists, #includes) to reflect |
7 # a rename. Expects "git diff --cached -M" to list a bunch of renames. | 7 # a rename. Expects "git diff --cached -M" to list a bunch of renames. |
8 # | 8 # |
9 # To use: | 9 # To use: |
10 # 1) git mv foo1 bar1; git mv foo2 bar2; etc. | 10 # 1) git mv foo1 bar1; git mv foo2 bar2; etc. |
11 # 2) *without committing*, ./tools/git/mass-rename.sh | 11 # 2) *without committing*, ./tools/git/mass-rename.sh |
12 # 3) look at git diff (without --cached) to see what the damage is | 12 # 3) look at git diff (without --cached) to see what the damage is |
13 # 4) commit, then use tools/sort-headers.py to fix #include ordering: | 13 # 4) commit, then use tools/sort-headers.py to fix #include ordering: |
14 # for f in $(git diff --name-only origin); do ./tools/sort-headers.py $f; done | 14 # for f in $(git diff --name-only origin); do ./tools/sort-headers.py $f; done |
15 | 15 |
16 # rename: | 16 DIR="$( cd "$( dirname "$0" )" && pwd )" |
17 # update all uses of |from| (first argument) to |to| (second argument). | |
18 rename() { | |
19 from="$1" | |
20 to="$2" | |
21 | |
22 # Fix references to the files in headers/gyp files. | |
23 echo "Processing: $from -> $to" | |
24 git grep -l "$from" -- '*.cc' '*.h' '*.m' '*.mm' '*.gyp*' | \ | |
25 xargs sed -i -e "s|$from|$to|" | |
26 | |
27 # Fix header guards. | |
28 if [ "${from##*.}" = "h" ]; then | |
29 hfrom=$(echo "$from" | tr 'a-z/' 'A-Z_' | sed -e 's|\..*$||') | |
30 hto=$(echo "$to" | tr 'a-z/' 'A-Z_' | sed -e 's|\..*$||') | |
31 echo "Processing: $hfrom -> $hto" | |
32 git grep -l "$hfrom" -- '*.cc' '*.h' '*.m' '*.mm' | \ | |
33 xargs sed -i -e "s|$hfrom|$hto|" | |
34 fi | |
35 | |
36 # Try again, stripping the first directory component -- helps with | |
37 # gyp files that rely on paths from the directory they're in. | |
38 from=$(echo "$from" | sed -e 's|^[^/]*/||') | |
39 to=$(echo "$to" | sed -e 's|^[^/]*/||') | |
40 echo "Processing: $from -> $to" | |
41 git grep -l "$from" -- '*.cc' '*.h' '*.m' '*.mm' '*.gyp*' | \ | |
42 xargs sed -i -e "s|$from|$to|" | |
43 } | |
44 | 17 |
45 # Make the 'read' used in the while loop split only on tabs/newlines. | 18 # Make the 'read' used in the while loop split only on tabs/newlines. |
46 IFS=$'\t\n' | 19 IFS=$'\t\n' |
47 | 20 |
48 git diff --cached --raw -M | while read attrs from to; do | 21 git diff --cached --raw -M | while read attrs from to; do |
49 type=$(echo "$attrs" | cut -d' ' -f5) | 22 type=$(echo "$attrs" | cut -d' ' -f5) |
50 if echo "$type" | grep -q "^R"; then | 23 if echo "$type" | grep -q "^R"; then |
51 # It's a rename. | 24 python $DIR/move_source_file.py --already-moved "$from" "$to" |
52 rename "$from" "$to" | |
53 else | 25 else |
54 echo "Skipping: $from -- not a rename?" | 26 echo "Skipping: $from -- not a rename?" |
55 fi | 27 fi |
56 done | 28 done |
57 | |
OLD | NEW |