xref: /aosp_15_r20/development/tools/repo_diff/README.md (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1*90c8c64dSAndroid Build Coastguard Worker# Repo Diff Trees
2*90c8c64dSAndroid Build Coastguard Worker
3*90c8c64dSAndroid Build Coastguard Workerrepo_diff_trees.py compares two repo source trees and outputs reports on the
4*90c8c64dSAndroid Build Coastguard Workerfindings.
5*90c8c64dSAndroid Build Coastguard Worker
6*90c8c64dSAndroid Build Coastguard WorkerThe ouput is in CSV and is easily consumable in a spreadsheet.
7*90c8c64dSAndroid Build Coastguard Worker
8*90c8c64dSAndroid Build Coastguard WorkerIn addition to importing to a spreadsheet, you can also create your own
9*90c8c64dSAndroid Build Coastguard WorkerData Studio dashboard like [this one](https://datastudio.google.com/open/0Bz6OwjyDcWYDbDJoQWtmRl8telU).
10*90c8c64dSAndroid Build Coastguard Worker
11*90c8c64dSAndroid Build Coastguard WorkerIf you wish to create your own dashboard follow the instructions below:
12*90c8c64dSAndroid Build Coastguard Worker
13*90c8c64dSAndroid Build Coastguard Worker1. Sync the two repo workspaces you wish to compare. Example:
14*90c8c64dSAndroid Build Coastguard Worker
15*90c8c64dSAndroid Build Coastguard Worker```
16*90c8c64dSAndroid Build Coastguard Workermkdir android-8.0.0_r1
17*90c8c64dSAndroid Build Coastguard Workercd android-8.0.0_r1
18*90c8c64dSAndroid Build Coastguard Workerrepo init \
19*90c8c64dSAndroid Build Coastguard Worker  --manifest-url=https://android.googlesource.com/platform/manifest \
20*90c8c64dSAndroid Build Coastguard Worker  --manifest-branch=android-8.0.0_r1
21*90c8c64dSAndroid Build Coastguard Worker# Adjust the number of parallel jobs to your needs
22*90c8c64dSAndroid Build Coastguard Workerrepo sync --current-branch --no-clone-bundle --no-tags --jobs=8
23*90c8c64dSAndroid Build Coastguard Workercd ..
24*90c8c64dSAndroid Build Coastguard Workermkdir android-8.0.0_r11
25*90c8c64dSAndroid Build Coastguard Workercd android-8.0.0_r11
26*90c8c64dSAndroid Build Coastguard Workerrepo init \
27*90c8c64dSAndroid Build Coastguard Worker  --manifest-url=https://android.googlesource.com/platform/manifest \
28*90c8c64dSAndroid Build Coastguard Worker  --manifest-branch=android-8.0.0_r11
29*90c8c64dSAndroid Build Coastguard Worker# Adjust the number of parallel jobs to your needs
30*90c8c64dSAndroid Build Coastguard Workerrepo sync --current-branch --no-clone-bundle --no-tags --jobs=8
31*90c8c64dSAndroid Build Coastguard Workercd ..
32*90c8c64dSAndroid Build Coastguard Worker```
33*90c8c64dSAndroid Build Coastguard Worker
34*90c8c64dSAndroid Build Coastguard Worker2. Run repo_diff_trees.py. Example:
35*90c8c64dSAndroid Build Coastguard Worker
36*90c8c64dSAndroid Build Coastguard Worker```
37*90c8c64dSAndroid Build Coastguard Workerpython repo_diff_trees.py --exclusions_file=android_exclusions.txt \
38*90c8c64dSAndroid Build Coastguard Worker  android-8.0.0_r1 android-8.0.0_r11
39*90c8c64dSAndroid Build Coastguard Worker```
40*90c8c64dSAndroid Build Coastguard Worker
41*90c8c64dSAndroid Build Coastguard Worker3. Create a [new Google spreadsheet](https://docs.google.com/spreadsheets/create).
42*90c8c64dSAndroid Build Coastguard Worker4. Import projects.csv to a new sheet.
43*90c8c64dSAndroid Build Coastguard Worker5. Create a [new data source in Data Studio](https://datastudio.google.com/datasources/create).
44*90c8c64dSAndroid Build Coastguard Worker6. Connect your new data source to the project.csv sheet in the Google spreadsheet.
45*90c8c64dSAndroid Build Coastguard Worker7. Add a "Count Diff Status" field by selecting the menu next to the "Diff
46*90c8c64dSAndroid Build Coastguard Worker   Status" field and selecting "Count".
47*90c8c64dSAndroid Build Coastguard Worker8. Copy the [Data Studio dashboard sample](https://datastudio.google.com/open/0Bz6OwjyDcWYDbDJoQWtmRl8telU).
48*90c8c64dSAndroid Build Coastguard Worker    Make sure you are logged into your Google account and you have agreed to Data Studio's terms of service. Once
49*90c8c64dSAndroid Build Coastguard Worker    this is done you should get a link to "Make a copy of this report".
50*90c8c64dSAndroid Build Coastguard Worker9. Select your own data source for your copy of the dashboard when prompted.
51*90c8c64dSAndroid Build Coastguard Worker10. You may see a "Configuration Incomplete" message under
52*90c8c64dSAndroid Build Coastguard Worker    the "Modified Projects" pie chart. To address this select the pie chart,
53*90c8c64dSAndroid Build Coastguard Worker    then replace the "Invalid Metric" field for "Count Diff Status".
54*90c8c64dSAndroid Build Coastguard Worker
55*90c8c64dSAndroid Build Coastguard Worker## Analysis method
56*90c8c64dSAndroid Build Coastguard Worker
57*90c8c64dSAndroid Build Coastguard Workerrepo_diff_trees.py goes through several stages when comparing two repo
58*90c8c64dSAndroid Build Coastguard Workersource trees:
59*90c8c64dSAndroid Build Coastguard Worker
60*90c8c64dSAndroid Build Coastguard Worker1. Match projects in source tree A with projects in source tree B.
61*90c8c64dSAndroid Build Coastguard Worker2. Diff projects that have a match.
62*90c8c64dSAndroid Build Coastguard Worker3. Find commits in source tree B that are not in source tree A.
63*90c8c64dSAndroid Build Coastguard Worker
64*90c8c64dSAndroid Build Coastguard WorkerThe first two steps are self explanatory. The method
65*90c8c64dSAndroid Build Coastguard Workerof finding commits only in B is explaned below.
66*90c8c64dSAndroid Build Coastguard Worker
67*90c8c64dSAndroid Build Coastguard Worker## Finding commits not upstream
68*90c8c64dSAndroid Build Coastguard Worker
69*90c8c64dSAndroid Build Coastguard WorkerAfter matching up projects in both source tree
70*90c8c64dSAndroid Build Coastguard Workerand diffing, the last stage is to iterate
71*90c8c64dSAndroid Build Coastguard Workerthrough each project matching pair and find
72*90c8c64dSAndroid Build Coastguard Workerthe commits that exist in the downstream project (B) but not the
73*90c8c64dSAndroid Build Coastguard Workerupstream project (A).
74*90c8c64dSAndroid Build Coastguard Worker
75*90c8c64dSAndroid Build Coastguard Worker'git cherry' is a useful tool that finds changes
76*90c8c64dSAndroid Build Coastguard Workerwhich exist in one branch but not another. It does so by
77*90c8c64dSAndroid Build Coastguard Workernot only by finding which commits that were merged
78*90c8c64dSAndroid Build Coastguard Workerto both branches, but also by matching cherry picked
79*90c8c64dSAndroid Build Coastguard Workercommits.
80*90c8c64dSAndroid Build Coastguard Worker
81*90c8c64dSAndroid Build Coastguard WorkerHowever, there are many instances where a change in one branch
82*90c8c64dSAndroid Build Coastguard Workercan have an equivalent in another branch without being a merge
83*90c8c64dSAndroid Build Coastguard Workeror a cherry pick. Some examples are:
84*90c8c64dSAndroid Build Coastguard Worker
85*90c8c64dSAndroid Build Coastguard Worker* Commits that were squashed with other commits
86*90c8c64dSAndroid Build Coastguard Worker* Commits that were reauthored
87*90c8c64dSAndroid Build Coastguard Worker
88*90c8c64dSAndroid Build Coastguard WorkerCherry pick will not recognize these commits as having an equivalent
89*90c8c64dSAndroid Build Coastguard Workeryet they clearly do.
90*90c8c64dSAndroid Build Coastguard Worker
91*90c8c64dSAndroid Build Coastguard WorkerThis is addressed in two steps:
92*90c8c64dSAndroid Build Coastguard Worker
93*90c8c64dSAndroid Build Coastguard Worker1. First listing the "git cherry" commits that will give us the
94*90c8c64dSAndroid Build Coastguard Worker   list of changes for which "git cherry" could not find an equivalent.
95*90c8c64dSAndroid Build Coastguard Worker2. Then we "git blame" the entire project's source tree and compile
96*90c8c64dSAndroid Build Coastguard Worker   a list of changes that actually have lines of code in the tree.
97*90c8c64dSAndroid Build Coastguard Worker3. Finally we find the intersection: 'git cherry' changes
98*90c8c64dSAndroid Build Coastguard Worker   that have lines of code in the final source tree.
99*90c8c64dSAndroid Build Coastguard Worker
100*90c8c64dSAndroid Build Coastguard Worker
101*90c8c64dSAndroid Build Coastguard Worker## Caveats
102*90c8c64dSAndroid Build Coastguard Worker
103*90c8c64dSAndroid Build Coastguard WorkerThe method described above has proven effective on Android
104*90c8c64dSAndroid Build Coastguard Workersource trees. It does have shortcomings.
105*90c8c64dSAndroid Build Coastguard Worker
106*90c8c64dSAndroid Build Coastguard Worker* It does not find commits that only delete lines of code.
107*90c8c64dSAndroid Build Coastguard Worker* It does take into accounts merge conflict resolutions.
108