merge-kernel: Gerrit namespace support

New optional argument "-N <namespace>" to specifiy the merge branch
prefix (Gerrit namespace). Default to 'stable-merge/linux' for Linux stable
release merges (merges against a release tag) or 'merge' for all other
merges.

BUG=b:183621345
TEST=Use script

Change-Id: Id59456c156146ea465087a4426e608861bb8b138
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2785649
Reviewed-by: William K Lin <wklin@google.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Commit-Queue: Guenter Roeck <groeck@chromium.org>
Tested-by: Guenter Roeck <groeck@chromium.org>
diff --git a/contrib/merge-kernel b/contrib/merge-kernel
index 6b99cf5..f73cdc1 100755
--- a/contrib/merge-kernel
+++ b/contrib/merge-kernel
@@ -38,6 +38,7 @@
 prereverts=() # List of patches to revert as part of merge, prior to merge
 dependency="" # No dependency
 Subject=""  # default subject
+namespace="" # default namespace
 
 # derived parameters
 skip_merge=0    # Skip actual merge and upload.
@@ -77,6 +78,8 @@
   -l change-id  Apply patch extracted from CL:change-id prior to merge.
                 May be repeated multiple times.
   -n            Send notification e-mail to ${notify_to}.
+  -N namespace  Namespace (branch prefix) to use
+                Default 'stable-merge/linux' or 'merge', depending on context
   -q dependency Add dependency (Cq-Depend: <dependency>)
   -p            Prepare for upload into Gerrit. Implied if -u is specified.
   -r            Name of branch to base merge on. Determined from stable
@@ -168,7 +171,7 @@
   local option
   local vtag
 
-  while getopts "b:c:d:fhl:nP:pq:r:R:st:uS:x:" option; do
+  while getopts "b:c:d:fhl:N:nP:pq:r:R:st:uS:x:" option; do
     case ${option} in
       b) bugs="${OPTARG}" ;;
       c) changeid="Change-Id: ${OPTARG}" ;;
@@ -180,6 +183,7 @@
       f) force=1 ;;
       l) changes+=("${OPTARG}") ;;
       n) notify=1 ;;
+      N) namespace="${OPTARG}" ;;
       p) prepare=1 ;;
       q) dependency="${OPTARG}" ;;
       r) rbranch="${OPTARG}" ;;
@@ -361,11 +365,20 @@
   # mbranch: Local branch used to execute the merge.
   readonly mbranch="${mcbranch}-${dtag}"
 
+  # Determine namespace to use if not provided
+  if [[ -z "${namespace}" ]]; then
+    if [[ "${tag}" == "${vtag}" ]]; then
+      namespace="stable-merge/linux"
+    else
+      namespace="merge"
+    fi
+  fi
+
   # obranch: chromeos branch used as reference.
   # May include local reverts from merge if necessary.
   # If necessary, a branch with this name will be created locally and
   # in the chromeos repository. It is necessary to perform the merge.
-  readonly obranch="stable-merge/linux/${dtag}"
+  readonly obranch="${namespace}/${dtag}"
 
   if [[ ${do_dryrun} -ne 0 ]]; then
     readonly dryrun="--dry-run"