1#!/bin/bash
2#
3#
4# Copyright (C) 2018 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# Note: have to be run from the root of the repository and you must ensure that
19# both remotes goog/mirror-aosp-main and goog/main exists.
20
21aosp_branch=goog/mirror-aosp-main
22local_branch=goog/main
23
24set -eu
25
26if [[ -d "frameworks/libs/binary_translation" ]]; then
27  cd "frameworks/libs/binary_translation"
28else
29  while ! [[ -d ".git" ]]; do
30    cd ..
31    if [[ "$PWD" == "/" ]]; then
32      echo "Couldn't find working directory"
33      exit 1
34    fi
35  done
36fi
37
38readarray -t files < <(
39  git diff "$aosp_branch" "$local_branch" |
40  grep '^diff --git' |
41  while read d g a b ; do
42    echo "${b:2}"
43  done
44)
45declare -A aosp_cls=() goog_cls=()
46for file in "${files[@]}"; do
47  readarray -t aosp_changes < <(
48    git log "$aosp_branch" "$file" |
49    grep '^commit ' |
50    cut -b 8-
51  )
52  declare -A aosp_changes_map
53  for aosp_change in "${aosp_changes[@]}"; do
54    aosp_change_id="$(
55      git log -n 1 "$aosp_change" | grep Change-Id: || true
56    )"
57    if ! [[ -z "${aosp_change_id}" ]]; then
58      aosp_changes_map["$aosp_change_id"]=https://googleplex-android-review.googlesource.com/q/commit:"$aosp_change"
59    fi
60  done
61  readarray -t goog_changes < <(
62    git log "$local_branch" "$file" |
63    grep '^commit ' |
64    cut -b 8-
65  )
66  declare -A goog_changes_map
67  for goog_change in "${goog_changes[@]}"; do
68    goog_change_id="$(
69      git log -n 1 "$goog_change" | grep Change-Id: || true
70    )"
71    if ! [[ -z "${goog_change_id}" ]]; then
72      goog_changes_map["$goog_change_id"]=https://googleplex-android-review.googlesource.com/q/commit:"$goog_change"
73    fi
74  done
75
76  for aosp_change_id in "${!aosp_changes_map[@]}"; do
77    if [[ "${goog_changes_map["$aosp_change_id"]:-absent}" = "absent" ]] ; then
78      aosp_cls[$aosp_change_id]="${aosp_changes_map[$aosp_change_id]}"
79    fi
80  done
81  for goog_change_id in "${!goog_changes_map[@]}"; do
82    if [[ "${aosp_changes_map["$goog_change_id"]:-absent}" = "absent" ]] ; then
83       goog_cls[$goog_change_id]="${goog_changes_map[$goog_change_id]}"
84    fi
85  done
86done
87if ((${#aosp_cls[@]}>0)); then
88  echo Only in AOSP:
89  for cl in "${!aosp_cls[@]}" ; do
90    echo "$cl => ${aosp_cls[$cl]}"
91  done
92fi
93if ((${#goog_cls[@]}>0)); then
94  echo Only in GOOG:
95  for cl in "${!goog_cls[@]}" ; do
96    echo "$cl => ${goog_cls[$cl]}"
97  done
98fi
99