Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: tools/git/mass-rename.sh

Issue 11358216: Consolidate mass-rename.sh and move_source_file.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reupload with similarity=30 to see the move diff. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/git/move_source_file.py » ('j') | tools/git/move_source_file.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « no previous file | tools/git/move_source_file.py » ('j') | tools/git/move_source_file.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698