|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +source "$(dirname "${BASH_SOURCE[0]}")/impl/util.sh" |
| 6 | + |
| 7 | +## |
| 8 | +## Prints a diff of a package in old and new scripts |
| 9 | +## directories. Operates in one of two modes. First mode is an |
| 10 | +## "ebuild" mode where it shows a diff of two ebuilds. The other mode |
| 11 | +## is an "other" mode where it shows diffs of all non-ebuild files |
| 12 | +## (ignoring Manifest files too). |
| 13 | +## |
| 14 | +## Parameters: |
| 15 | +## -h: this help |
| 16 | +## -r <name>: New package name (useful when package got renamed) |
| 17 | +## |
| 18 | +## Positional: |
| 19 | +## 1: mode, "ebuild" (or "e") or "other" (or "o") |
| 20 | +## 2: path to old scripts repository |
| 21 | +## 3: path to new scripts repository |
| 22 | +## 4: package name (but see -r flag too) |
| 23 | +## 5: old version (for "ebuild" mode only) |
| 24 | +## 6: new version (for "ebuild" mode only) |
| 25 | +## |
| 26 | + |
| 27 | +renamed= |
| 28 | + |
| 29 | +while [[ ${#} -gt 0 ]]; do |
| 30 | + case ${1} in |
| 31 | + -h) |
| 32 | + print_help |
| 33 | + exit 0 |
| 34 | + ;; |
| 35 | + -r) |
| 36 | + renamed=${2} |
| 37 | + shift 2 |
| 38 | + ;; |
| 39 | + --) |
| 40 | + shift |
| 41 | + break |
| 42 | + ;; |
| 43 | + -*) |
| 44 | + fail "unknown flag ${1@Q}" |
| 45 | + ;; |
| 46 | + *) |
| 47 | + break |
| 48 | + ;; |
| 49 | + esac |
| 50 | +done |
| 51 | + |
| 52 | +if [[ ${#} -lt 1 ]]; then |
| 53 | + fail 'Use -h to get help' |
| 54 | +fi |
| 55 | + |
| 56 | +mode=${1}; shift |
| 57 | + |
| 58 | +case ${mode} in |
| 59 | + ebuild|ebuil|ebui|ebu|eb|e) |
| 60 | + mode=e |
| 61 | + if [[ ${#} -ne 5 ]]; then |
| 62 | + fail 'Expected five positional parameters: a path to old and new scripts repositories, a package name, and old a new version of package' |
| 63 | + fi |
| 64 | + ;; |
| 65 | + other|othe|oth|ot|o) |
| 66 | + mode=o |
| 67 | + # expect at least three parameters, if more are given, they |
| 68 | + # will be ignored, to allow changing mode from ebuild to other |
| 69 | + # without the need for removing versions from the command |
| 70 | + # invocation |
| 71 | + if [[ ${#} -lt 3 ]]; then |
| 72 | + fail 'Expected three positional parameters: a path to old and new scripts repositories, and a package name' |
| 73 | + fi |
| 74 | + ;; |
| 75 | +esac |
| 76 | + |
| 77 | +old_scripts=${1} |
| 78 | +new_scripts=${2} |
| 79 | +# old and new package name |
| 80 | +old_package=${3} |
| 81 | +new_package=${renamed:-${3}} |
| 82 | + |
| 83 | +gentoo_path=sdk_container/src/third_party/portage-stable |
| 84 | +overlay_path=sdk_container/src/third_party/coreos-overlay |
| 85 | +old_gentoo_path=${old_scripts}/${gentoo_path}/${old_package} |
| 86 | +old_overlay_path=${old_scripts}/${overlay_path}/${old_package} |
| 87 | +new_gentoo_path=${new_scripts}/${gentoo_path}/${new_package} |
| 88 | +new_overlay_path=${new_scripts}/${overlay_path}/${new_package} |
| 89 | + |
| 90 | +if [[ -e ${old_gentoo_path} ]] && [[ -e ${old_overlay_path} ]]; then |
| 91 | + fail "Package ${old_package@Q} exists in both gentoo and overlay in old scripts" |
| 92 | +fi |
| 93 | + |
| 94 | +if [[ -e ${new_gentoo_path} ]] && [[ -e ${new_overlay_path} ]]; then |
| 95 | + fail "Package ${new_package@Q} exists in both gentoo and overlay in new scripts" |
| 96 | +fi |
| 97 | + |
| 98 | +if [[ ${mode} = e ]]; then |
| 99 | + old_version=${4} |
| 100 | + new_version=${5} |
| 101 | + old_gentoo_ebuild=${old_gentoo_path}/${old_package#*/}-${old_version}.ebuild |
| 102 | + old_overlay_ebuild=${old_overlay_path}/${old_package#*/}-${old_version}.ebuild |
| 103 | + new_gentoo_ebuild=${new_gentoo_path}/${new_package#*/}-${new_version}.ebuild |
| 104 | + new_overlay_ebuild=${new_overlay_path}/${new_package#*/}-${new_version}.ebuild |
| 105 | + |
| 106 | + old_path='' |
| 107 | + new_path='' |
| 108 | + |
| 109 | + if [[ -e ${old_gentoo_ebuild} ]]; then |
| 110 | + old_path=${old_gentoo_ebuild} |
| 111 | + fi |
| 112 | + if [[ -e ${old_overlay_ebuild} ]]; then |
| 113 | + old_path=${old_overlay_ebuild} |
| 114 | + fi |
| 115 | + |
| 116 | + if [[ -e ${new_gentoo_ebuild} ]]; then |
| 117 | + new_path=${new_gentoo_ebuild} |
| 118 | + fi |
| 119 | + if [[ -e ${new_overlay_ebuild} ]]; then |
| 120 | + new_path=${new_overlay_ebuild} |
| 121 | + fi |
| 122 | + |
| 123 | + if [[ -z ${old_path} ]]; then |
| 124 | + fail "Old version ${old_version@Q} does not exist neither in overlay nor in gentoo" |
| 125 | + fi |
| 126 | + |
| 127 | + if [[ -z ${new_path} ]]; then |
| 128 | + fail "New version ${new_version@Q} does not exist neither in overlay nor in gentoo" |
| 129 | + fi |
| 130 | + |
| 131 | + diff --color --unified=3 "${old_path}" "${new_path}" || : |
| 132 | +else |
| 133 | + old_path=${old_gentoo_path} |
| 134 | + new_path=${new_gentoo_path} |
| 135 | + |
| 136 | + if [[ -e ${old_overlay_path} ]]; then |
| 137 | + old_path=${old_overlay_path} |
| 138 | + fi |
| 139 | + |
| 140 | + if [[ -e ${new_overlay_path} ]]; then |
| 141 | + new_path=${new_overlay_path} |
| 142 | + fi |
| 143 | + |
| 144 | + diff --color --recursive --unified=3 --new-file --exclude='*.ebuild' --exclude='Manifest' "${old_path}" "${new_path}" || : |
| 145 | +fi |
0 commit comments