From 80b138ca1baf66de5cdb3e94a03b483d467ddaa2 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Sat, 2 Oct 2021 21:19:49 +0200 Subject: [PATCH] Add support for downloading changes for different projects Now it is possible to download a change for a project, which is not the current one, i.e., to download a change for project B you don't have to be in the workspace of project B to download it. A new key (k) was added to the gerrit-download-transient to download changes for known projects. Change-Id: Ie4d55bced47af0575fce3a4a01aea6e0345771e1 --- README.md | 6 +++-- gerrit.el | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f40c680..16628cc 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Gerrit is a great code review tool and a great git hosting serivce. This package provides an emacs interface for * uploading changes (`gerrit-upload`) -* downloading changes (`gerrit-download`) +* downloading changes (`gerrit-download` and `gerrit-download-transient`) * creating a dashboard (`gerrit-dashboard`) * creating buffers that contain details about gerrit topics an gerrit changes (`gerrit-section-topic-info` and `gerrit-section-change-info`). @@ -114,7 +114,9 @@ Now you can list the secrets using `secrets-show-secrets`. October 2021: * Add a new transient called `gerrit-download-transient`, which will replace -the `gerrit-download` function in the future. + the `gerrit-download` function in the future. +* Add support for downloading changes in arbitrary git workspaces using + `gerrit-download-transient`. ## Screenshots diff --git a/gerrit.el b/gerrit.el index b91d256..c006422 100644 --- a/gerrit.el +++ b/gerrit.el @@ -163,6 +163,34 @@ gerrit-download is used." 'project (the project name)" ) +;; TODO introduce a function? +(defcustom gerrit-project-to-local-workspace-alist nil + "This alist can be used for specifying the 'known' gerrit projects. + +The alist is needed for determining the workspace directory for +certain gerrit projects. + +Each element is a list comprising ((PROJECT BRANCH) WORKSPACE) ..." + :group 'gerrit + :type '(alist :key-type (list (symbol :tag "Project") + (string :tag "Branch")) + :value-type (string :tag "Workspace Directory")) + ) +;; Example: +;; (setq gerrit-project-to-local-workspace-alist +;; '( +;; (("software/pro1" "branch1") "~/sandbox/pro1") +;; (("software/pro2" "branch2") "~/sandbox/pro2") +;; )) + +(defcustom gerrit-interesting-open-changes-filter "is:open" + "Filter string used for querying gerrit changes. + +If you are interested only in the changes for certain projects, +you can use 'is:open (project:A OR project:B OR project:C)'" + :group 'gerrit + :type 'string) + (defun gerrit-download-format-change (change) (let (columns) ;; can this be implemented in an easier way? @@ -1235,7 +1263,10 @@ gerrit-upload: (current cmd: %(concat (gerrit-upload-create-git-review-cmd))) :argument "branch=") (defun gerrit-download:--in-current-repo (changenr) - "Download a gerrit change CHANGENR for the current project into the current workspace." + "Download a gerrit change CHANGENR for the current project. + +The download of the change is performed in the workspace of the +current project." (interactive (list (gerrit--select-change-from-matching-changes @@ -1251,10 +1282,43 @@ gerrit-upload: (current cmd: %(concat (gerrit-upload-create-git-review-cmd))) nil)))))))) (gerrit-download--new changenr)) +(defun gerrit-download:--in-known-repo (changenr) + "Download a gerrit change CHANGENR for a known project. + +The download of the change is performed in the corresponding +workspace of the project." + (interactive + (list + (let + ((gerrit-change-singleline-columns '(number branch project subject))) + (gerrit--select-change-from-matching-changes + ;; TODO add support for selecting branches (what if + ;; gerrit-interesting-open-changes-filter already contains + ;; branch:...?) + gerrit-interesting-open-changes-filter)))) + + ;; 1) get change metadata + ;; 2) determine workspace directory (based on branch and projectname) + ;; 3) switch to workspace + ;; 4) download change + (let* ((change-metadata (car (gerrit-rest-change-query changenr))) + (project-name (alist-get 'project change-metadata)) + (branch (alist-get 'branch change-metadata)) + (workspace-directory (or (cdr (assoc (list project-name branch) + gerrit-project-to-local-workspace-alist)) + ;; TODO completion + write them to file + (read-directory-name + (format "Enter directory for project %s" project-name)))) + + (default-directory workspace-directory)) + ;; (message "changeinfo: name: %s, branch: %s -> workspace: %s" + ;; project-name branch workspace-directory) + (gerrit--download-change change-metadata))) + (transient-define-prefix gerrit-download-transient () "Transient used for downloading changes" ;; download in current repo (key c: current) - ;; TODO download in all known projects (key o: all/other) + ;; download in all known projects (key k: known) ;; download specific branch (depends on project!) ["Arguments" @@ -1264,7 +1328,7 @@ gerrit-upload: (current cmd: %(concat (gerrit-upload-create-git-review-cmd))) ;; TODO display somewhere the name of the current repo (not sure if ;; emacs-transient supports this) ("c" "In current repo" gerrit-download:--in-current-repo) - ;; ("k" "In known repo" gerrit-download:--in-known-repo) + ("k" "In known repo" gerrit-download:--in-known-repo) ]) ;; deprecated