Skip to content

Commit ab3d78e

Browse files
committed
Improve support for selecting and downloading changes
A new interactive function called `gerrit-download-and-open-overview' was added which downloads the change and opens an magit-commit buffer using `magit-show-commit'. (It the downloaded change is at the top of a relation chain, the other commits are currently not displayed by this `gerrit-download-and-open-overview' function. Closes: #19 Change-Id: Ie3ed04a8f212cb8c0a98745d1dca4f680f420642
1 parent 24ebff7 commit ab3d78e

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

gerrit.el

+51-3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ gerrit-download is used."
159159
"'project (the project name)"
160160
)
161161

162+
;; TODO document this variable
163+
;; (setq gerrit-project-to-local-workspace-alist
164+
;; '(
165+
;; (("software/pro1" . "branch1") . "~/sandbox/pro1")
166+
;; (("software/pro2" . "branch2") . "~/sandbox/pro2")
167+
;; ))
168+
(defvar gerrit-project-to-local-workspace-alist nil)
169+
170+
;; TODO docs missing
171+
;; mention (project:A OR project:B OR project:C)
172+
(defvar gerrit-interesting-open-changes-filter "is:open")
173+
162174
(defun gerrit-download-format-change (change)
163175
(let (columns)
164176
;; can this be implemented in an easier way?
@@ -215,6 +227,7 @@ This refspec is a string of the form 'refs/changes/xx/xx/x'.
215227
;; (e.g. if ssh-add was not called) this async call runs
216228
;; magit-process-password-prompt-regexps (used in magit-process-filter)
217229
;; which is called in magit-start-process
230+
;; (see https://github.com/magit/magit/issues/4323)
218231
(magit-run-git-async "fetch"
219232
(gerrit-get-remote)
220233
(gerrit-download--get-refspec change-metadata))
@@ -1215,6 +1228,7 @@ gerrit-upload: (current cmd: %(concat (gerrit-upload-create-git-review-cmd)))
12151228

12161229
(defun gerrit--select-change-from-matching-changes (search-string)
12171230
;; see https://gerrit-review.googlesource.com/Documentation/user-search.html
1231+
;; clients can let-bind `gerrit-change-singleline-columns'
12181232
(let* ((open-changes (seq-map #'reviewgerrit-download-format-change
12191233
(gerrit-rest-change-query
12201234
(or search-string "is:open")
@@ -1228,15 +1242,49 @@ gerrit-upload: (current cmd: %(concat (gerrit-upload-create-git-review-cmd)))
12281242
"Download change with CHANGENR from the gerrit server."
12291243
(interactive
12301244
(list
1231-
(gerrit--select-change-from-matching-changes
1232-
(concat "status:open project:"
1233-
(gerrit-get-current-project)))))
1245+
(let
1246+
((gerrit-change-singleline-columns '(number branch project subject)))
1247+
(gerrit--select-change-from-matching-changes
1248+
(concat "status:open project:"
1249+
(gerrit-get-current-project))))))
12341250

12351251
(gerrit--init-accounts)
12361252
(if gerrit-use-gitreview-interface
12371253
(gerrit-download--gitreview changenr)
12381254
(gerrit-download--new changenr)))
12391255

1256+
;; TODO split this up into two parts (one that downloads the change and one that opens the overview page using magit-show-commit
1257+
(defun gerrit-download-and-open-overview (changenr)
1258+
;; since a simple "is:open" query might return a lot of gerrit-changes, it
1259+
;; is possible to filter the returned results by setting an variable
1260+
;; called `gerrit-interesting-open-changes-filter'.
1261+
(interactive (list
1262+
(let
1263+
((gerrit-change-singleline-columns '(number branch project subject)))
1264+
(gerrit--select-change-from-matching-changes
1265+
gerrit-interesting-open-changes-filter))))
1266+
1267+
;; 1) get change metadata
1268+
;; 2) determine workspace directory (based on branch and projectname)
1269+
;; 3) switch to workspace
1270+
;; 4) download change
1271+
;; 5) display commit
1272+
(let* ((change-metadata (car (gerrit-rest-change-query changenr)))
1273+
(project-name (alist-get 'project change-metadata))
1274+
(branch (alist-get 'branch change-metadata))
1275+
(workspace-directory (or (cdr (assoc (cons project-name branch)
1276+
gerrit-project-to-local-workspace-alist))
1277+
;; TODO completion + write them to file
1278+
(read-directory-name
1279+
(format "Enter directory for project %s" project-name)))))
1280+
(let ((default-directory workspace-directory))
1281+
(message "changeinfo: name: %s, branch: %s -> workspace: %s"
1282+
project-name branch workspace-directory)
1283+
(gerrit-download changenr) ;; this is async
1284+
;; TODO run magit-show-commit
1285+
;; only when the above change is downloaded to avoid window-flickering
1286+
(magit-show-commit "HEAD"))))
1287+
12401288
(defun gerrit-upload ()
12411289
(interactive)
12421290
(if gerrit-use-gitreview-interface

0 commit comments

Comments
 (0)