Commit ddce6ce4 authored by Jonas Bernoulli's avatar Jonas Bernoulli

sections: Use oref instead of dedicated slot accessors

parent 645c6c1f
......@@ -113,10 +113,10 @@ so causes the change to be applied to the index as well."
(`(,_ files) (magit-apply-diffs it args)))))
(defun magit-apply--section-content (section)
(buffer-substring-no-properties (if (eq (magit-section-type section) 'hunk)
(magit-section-start section)
(magit-section-content section))
(magit-section-end section)))
(buffer-substring-no-properties (if (eq (oref section type) 'hunk)
(oref section start)
(oref section content))
(oref section end)))
(defun magit-apply-diffs (sections &rest args)
(setq sections (magit-apply--get-diffs sections))
......@@ -134,8 +134,8 @@ so causes the change to be applied to the index as well."
(magit-apply--section-content section))))
(defun magit-apply-hunks (sections &rest args)
(let ((section (magit-section-parent (car sections))))
(when (string-match "^diff --cc" (magit-section-value section))
(let ((section (oref (car sections) parent)))
(when (string-match "^diff --cc" (oref section value))
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
(magit-apply-patch section args
(concat (oref section header)
......@@ -145,7 +145,7 @@ so causes the change to be applied to the index as well."
(defun magit-apply-hunk (section &rest args)
(when (string-match "^diff --cc" (magit-section-parent-value section))
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
(magit-apply-patch (magit-section-parent section) args
(magit-apply-patch (oref section parent) args
(concat (magit-diff-file-header section)
(magit-apply--section-content section))))
......@@ -154,14 +154,14 @@ so causes the change to be applied to the index as well."
(user-error "Not enough context to apply region. Increase the context"))
(when (string-match "^diff --cc" (magit-section-parent-value section))
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
(magit-apply-patch (magit-section-parent section) args
(magit-apply-patch (oref section parent) args
(concat (magit-diff-file-header section)
(magit-diff-hunk-region-patch section args))))
(defun magit-apply-patch (section:s args patch)
(let* ((files (if (atom section:s)
(list (magit-section-value section:s))
(mapcar 'magit-section-value section:s)))
(list (oref section:s value))
(--map (oref it value) section:s)))
(command (symbol-name this-command))
(command (if (and command (string-match "^magit-\\([^-]+\\)" command))
(match-string 1 command)
......@@ -182,18 +182,18 @@ so causes the change to be applied to the index as well."
(defun magit-apply--get-selection ()
(or (magit-region-sections '(hunk file) t)
(let ((section (magit-current-section)))
(pcase (magit-section-type section)
(pcase (oref section type)
((or `hunk `file) section)
((or `staged `unstaged `untracked
`stashed-index `stashed-worktree `stashed-untracked)
(magit-section-children section))
(oref section children))
(_ (user-error "Cannot apply this, it's not a change"))))))
(defun magit-apply--get-diffs (sections)
(magit-section-case
([file diffstat]
(--map (or (magit-get-section
(append `((file . ,(magit-section-value it)))
(append `((file . ,(oref it value)))
(magit-section-ident magit-root-section)))
(error "Cannot get required diff headers"))
sections))
......@@ -228,7 +228,7 @@ at point, stage the file but not its content."
(`(unstaged file t) (magit-apply-diff it "--cached"))
(`(unstaged files t) (magit-apply-diffs it "--cached"))
(`(unstaged list t) (magit-apply-diffs it "--cached"))
(`(unstaged file nil) (magit-stage-1 "-u" (list (magit-section-value it))))
(`(unstaged file nil) (magit-stage-1 "-u" (list (oref it value))))
(`(unstaged files nil) (magit-stage-1 "-u" (magit-region-values nil t)))
(`(unstaged list nil) (magit-stage-modified))
(`(staged ,_ ,_) (user-error "Already staged"))
......@@ -279,7 +279,7 @@ ignored) files."
(defun magit-stage-untracked (&optional intent)
(let* ((section (magit-current-section))
(files (pcase (magit-diff-scope)
(`file (list (magit-section-value section)))
(`file (list (oref section value)))
(`files (magit-region-values nil t))
(`list (magit-untracked-files))))
plain repos)
......@@ -296,9 +296,9 @@ ignored) files."
(mapc #'magit-turn-on-auto-revert-mode-if-desired plain)))
(dolist (repo repos)
(save-excursion
(goto-char (magit-section-start
(magit-get-section
`((file . ,repo) (untracked) (status)))))
(goto-char (oref (magit-get-section
`((file . ,repo) (untracked) (status)))
start))
(let* ((topdir (magit-toplevel))
(package
(and (equal (bound-and-true-p borg-user-emacs-directory)
......@@ -341,7 +341,7 @@ ignored) files."
(`(staged file t) (magit-apply-diff it "--reverse" "--cached"))
(`(staged files t) (magit-apply-diffs it "--reverse" "--cached"))
(`(staged list t) (magit-apply-diffs it "--reverse" "--cached"))
(`(staged file nil) (magit-unstage-1 (list (magit-section-value it))))
(`(staged file nil) (magit-unstage-1 (list (oref it value))))
(`(staged files nil) (magit-unstage-1 (magit-region-values nil t)))
(`(staged list nil) (magit-unstage-all))
(`(committed ,_ ,_) (if magit-unstage-committed
......@@ -414,8 +414,8 @@ without requiring confirmation."
(if (eq (magit-diff-type section) 'unstaged)
(funcall apply section "--reverse")
(if (magit-anything-unstaged-p
nil (if (eq (magit-section-type section) 'file)
(magit-section-value section)
nil (if (eq (oref section type) 'file)
(oref section value)
(magit-section-parent-value section)))
(progn (let ((inhibit-magit-refresh t))
(funcall apply section "--reverse" "--cached")
......@@ -435,8 +435,8 @@ without requiring confirmation."
(if (eq (magit-diff-type section) 'unstaged)
(funcall apply sections "--reverse")
(if (magit-anything-unstaged-p
nil (if (eq (magit-section-type section) 'file)
(magit-section-value section)
nil (if (eq (oref section type) 'file)
(oref section value)
(magit-section-parent-value section)))
(progn (let ((inhibit-magit-refresh t))
(funcall apply sections "--reverse" "--cached")
......@@ -453,7 +453,7 @@ without requiring confirmation."
(status (magit-file-status))
files delete resurrect rename discard discard-new resolve)
(dolist (section sections)
(let ((file (magit-section-value section)))
(let ((file (oref section value)))
(push file files)
(pcase (cons (pcase type
(`staged ?X)
......@@ -536,7 +536,7 @@ without requiring confirmation."
(magit-call-git "reset" "--" orig))))))
(defun magit-discard-files--discard (sections new-files)
(let ((files (mapcar #'magit-section-value sections)))
(let ((files (--map (oref it value) sections)))
(when (magit-confirm-files
'discard (append files new-files)
(format "Discard %s changes in" (magit-diff-type)))
......@@ -548,7 +548,7 @@ without requiring confirmation."
(let ((binaries (magit-staged-binary-files)))
(when binaries
(setq sections
(--filter (not (member (magit-section-value it) binaries))
(--filter (not (member (oref it value) binaries))
sections)))
(cond ((= (length sections) 1)
(magit-discard-apply (car sections) 'magit-apply-diff))
......@@ -604,8 +604,9 @@ so causes the change to be applied to the index as well."
(defun magit-reverse-files (sections args)
(-let [(binaries sections)
(let ((bs (magit-staged-binary-files)))
(--separate (member (magit-section-value it) bs) sections))]
(when (magit-confirm-files 'reverse (mapcar #'magit-section-value sections))
(--separate (member (oref it value) bs)
sections))]
(when (magit-confirm-files 'reverse (--map (oref it value) sections))
(if (= (length sections) 1)
(magit-reverse-apply (car sections) 'magit-apply-diff args)
(magit-reverse-apply sections 'magit-apply-diffs args)))
......
......@@ -51,8 +51,9 @@ This function will:
(when (derived-mode-p 'magit-mode)
(-when-let (hidden-sections (bookmark-prop-get bookmark
'magit-hidden-sections))
(--each (magit-section-children magit-root-section)
(if (member (cons (magit-section-type it) (magit-section-value it))
(--each (oref magit-root-section children)
(if (member (cons (oref it type)
(oref it value))
hidden-sections)
(magit-section-hide it)
(magit-section-show it)))))
......@@ -87,9 +88,10 @@ specifies additional properties to store in the bookmark."
(when (derived-mode-p 'magit-mode)
(bookmark-prop-set
bookmark 'magit-hidden-sections
(--map (cons (magit-section-type it) (magit-section-value it))
(-filter #'magit-section-hidden
(magit-section-children magit-root-section)))))
(--map (cons (oref it type)
(oref it value))
(--filter (oref it hidden)
(oref magit-root-section children)))))
(when make-props
(pcase-dolist (`(,prop . ,value) (apply make-props magit-refresh-args))
(bookmark-prop-set bookmark prop value)))
......@@ -340,12 +342,12 @@ specifies additional properties to store in the bookmark."
(magit-args . ,args)
(magit-files . ,files)
(magit-hidden-sections
. ,(--map `(,(magit-section-type it)
. ,(--map `(,(oref it type)
. ,(replace-regexp-in-string (regexp-quote stash)
magit-buffer-revision-hash
(magit-section-value it)))
(-filter #'magit-section-hidden
(magit-section-children magit-root-section))))))))
(oref it value)))
(--filter (oref it hidden)
(oref magit-root-section children))))))))
;;; Submodules
......
......@@ -792,14 +792,14 @@ If no DWIM context is found, nil is returned."
((derived-mode-p 'magit-stash-mode)
(cons 'commit
(magit-section-case
(commit (magit-section-value it))
(commit (oref it value))
(file (-> it
magit-section-parent
magit-section-value))
(oref parent)
(oref value)))
(hunk (-> it
magit-section-parent
magit-section-parent
magit-section-value)))))
(oref parent)
(oref parent)
(oref value))))))
((derived-mode-p 'magit-revision-mode)
(cons 'commit (car magit-refresh-args)))
((derived-mode-p 'magit-diff-mode)
......@@ -808,10 +808,10 @@ If no DWIM context is found, nil is returned."
(magit-section-case
([* unstaged] 'unstaged)
([* staged] 'staged)
(unpushed (magit-section-value it))
(unpulled (magit-section-value it))
(unpushed (oref it value))
(unpulled (oref it value))
(branch (let ((current (magit-get-current-branch))
(atpoint (magit-section-value it)))
(atpoint (oref it value)))
(if (equal atpoint current)
(--if-let (magit-get-upstream-branch)
(format "%s...%s" it current)
......@@ -821,8 +821,8 @@ If no DWIM context is found, nil is returned."
(format "%s...%s"
(or current "HEAD")
atpoint))))
(commit (cons 'commit (magit-section-value it)))
(stash (cons 'stash (magit-section-value it)))))))
(commit (cons 'commit (oref it value)))
(stash (cons 'stash (oref it value)))))))
(defun magit-diff-read-range-or-commit (prompt &optional secondary-default mbase)
"Read range or revision with special diff range treatment.
......@@ -1003,8 +1003,8 @@ for a revision."
(with-current-buffer buffer
(let ((prev (car magit-refresh-args)))
(unless (equal rev prev)
(dolist (child (cdr (magit-section-children magit-root-section)))
(when (eq (magit-section-type child) 'file)
(dolist (child (cdr (oref magit-root-section children)))
(when (eq (oref child type) 'file)
(magit-section-cache-visibility child)))))))
(magit-mode-setup #'magit-revision-mode rev nil args files)))
......@@ -1332,11 +1332,11 @@ or `HEAD'."
(let ((section (magit-current-section)))
(cl-case scope
((file files)
(setq section (car (magit-section-children section))))
(setq section (car (oref section children))))
(list
(setq section (car (magit-section-children section)))
(setq section (car (oref section children)))
(when section
(setq section (car (magit-section-children section))))))
(setq section (car (oref section children))))))
(and
;; Unmerged files appear in the list of staged changes
;; but unlike in the list of unstaged changes no diffs
......@@ -1345,7 +1345,7 @@ or `HEAD'."
;; Currently the `hunk' type is also abused for file
;; mode changes, which we are not interested in here.
;; Such sections have no value.
(magit-section-value section)
(oref section value)
section))))
(defun magit-diff-visit--offset (file rev hunk-start line-offset)
......@@ -1379,9 +1379,9 @@ or `HEAD'."
(+ hunk-start line-offset offset)))
(defun magit-diff-hunk-line (section)
(let* ((value (magit-section-value section))
(let* ((value (oref section value))
(prefix (- (length value) 2))
(cpos (marker-position (magit-section-content section)))
(cpos (marker-position (oref section content)))
(stop (line-number-at-pos))
(cstart (save-excursion (goto-char cpos)
(line-number-at-pos)))
......@@ -1410,11 +1410,12 @@ or `HEAD'."
(list line offset)))
(defun magit-diff-hunk-column (section)
(if (or (< (point) (magit-section-content section))
(if (or (< (point)
(oref section content))
(save-excursion (beginning-of-line) (looking-at-p "-")))
0
(max 0 (- (+ (current-column) 2)
(length (magit-section-value section))))))
(length (oref section value))))))
(defun magit-diff-visit-directory (directory &optional other-window)
(if (equal (magit-toplevel directory)
......@@ -1470,15 +1471,15 @@ commit or stash at point, then prompt for a commit."
(t
(magit-section-case
(branch
(setq rev (magit-ref-maybe-qualify (magit-section-value it)))
(setq rev (magit-ref-maybe-qualify (oref it value)))
(setq cmd 'magit-show-commit)
(setq buf (magit-mode-get-buffer 'magit-revision-mode)))
(commit
(setq rev (magit-section-value it))
(setq rev (oref it value))
(setq cmd 'magit-show-commit)
(setq buf (magit-mode-get-buffer 'magit-revision-mode)))
(stash
(setq rev (magit-section-value it))
(setq rev (oref it value))
(setq cmd 'magit-stash-show)
(setq buf (magit-mode-get-buffer 'magit-stash-mode))))))
(if rev
......@@ -1643,8 +1644,8 @@ section or a child thereof."
(interactive)
(--if-let (magit-get-section
(append (magit-section-case
([file diffstat] `((file . ,(magit-section-value it))))
(file `((file . ,(magit-section-value it)) (diffstat)))
([file diffstat] `((file . ,(oref it value))))
(file `((file . ,(oref it value)) (diffstat)))
(t '((diffstat))))
(magit-section-ident magit-root-section)))
(magit-section-goto it)
......@@ -1862,13 +1863,13 @@ section or a child thereof."
(magit-insert-heading)
(while (not (or (eobp) (looking-at "^[^-+\s\\]")))
(forward-line))
(setf (magit-section-end it) (point))
(setf (magit-section-washer it) #'magit-diff-paint-hunk)))
(oset it end (point))
(oset it washer 'magit-diff-paint-hunk)))
t))
(defun magit-diff-expansion-threshold (section)
"Keep new diff sections collapsed if washing takes too long."
(and (memq (magit-section-type section) '(file))
(and (eq (oref section type) 'file)
(> (float-time (time-subtract (current-time) magit-refresh-start-time))
magit-diff-expansion-threshold)
'hide))
......@@ -2229,20 +2230,22 @@ Do not confuse this with `magit-diff-scope' (which see)."
'undefined)) ; i.e. committed and staged
(t 'committed))))
((derived-mode-p 'magit-status-mode)
(let ((stype (magit-section-type it)))
(let ((stype (oref it type)))
(if (memq stype '(staged unstaged tracked untracked))
stype
(pcase stype
(`file (let* ((parent (magit-section-parent it))
(type (magit-section-type parent)))
(`file (let* ((parent (oref it parent))
(type (oref parent type)))
(if (eq type 'file)
(magit-diff-type parent)
type)))
(`hunk (-> it magit-section-parent magit-section-parent
magit-section-type))))))
(`hunk (-> it
(oref parent)
(oref parent)
(oref type)))))))
((derived-mode-p 'magit-log-mode)
(if (or (and (magit-section-match 'commit section)
(magit-section-children section))
(oref section children))
(magit-section-match [* file commit] section))
'committed
'undefined))
......@@ -2274,10 +2277,10 @@ actually a `diff' but a `diffstat' section."
(when (and section
(or (not strict)
(and (not (eq (magit-diff-type section) 'untracked))
(not (eq (--when-let (magit-section-parent section)
(magit-section-type it))
(not (eq (--when-let (oref section parent)
(oref it type))
'diffstat)))))
(pcase (list (magit-section-type section)
(pcase (list (oref section type)
(and siblings t)
(magit-diff-use-hunk-region-p)
ssection)
......@@ -2308,7 +2311,7 @@ actually a `diff' but a `diffstat' section."
(defun magit-diff-unhighlight (section selection)
"Remove the highlighting of the diff-related SECTION."
(when (eq (magit-section-type section) 'hunk)
(when (eq (oref section type) 'hunk)
(magit-diff-paint-hunk section selection nil)
t))
......@@ -2319,7 +2322,7 @@ return nil. If SELECTION is non-nil, then it is a list of sections
selected by the region, including SECTION. All of these sections
are highlighted."
(if (and (magit-section-match 'commit section)
(magit-section-children section))
(oref section children))
(progn (if selection
(dolist (section selection)
(magit-diff-highlight-list section selection))
......@@ -2344,37 +2347,36 @@ are highlighted."
(_ (magit-section-highlight section nil))))
(defun magit-diff-highlight-list (section &optional selection)
(let ((beg (magit-section-start section))
(cnt (magit-section-content section))
(end (magit-section-end section)))
(let ((beg (oref section start))
(cnt (oref section content))
(end (oref section end)))
(when (or (eq this-command 'mouse-drag-region)
(not selection))
(unless (and (region-active-p)
(<= (region-beginning)
(magit-section-start section)))
(<= (region-beginning) beg))
(magit-section-make-overlay beg cnt 'magit-section-highlight))
(unless (magit-section-hidden section)
(dolist (child (magit-section-children section))
(unless (oref section hidden)
(dolist (child (oref section children))
(when (or (eq this-command 'mouse-drag-region)
(not (and (region-active-p)
(<= (region-beginning)
(magit-section-start child)))))
(oref child start)))))
(magit-diff-highlight-recursive child selection)))))
(when magit-diff-highlight-hunk-body
(magit-section-make-overlay (1- end) end 'magit-section-highlight))))
(defun magit-diff-highlight-file (section &optional selection)
(magit-diff-highlight-heading section selection)
(unless (magit-section-hidden section)
(dolist (child (magit-section-children section))
(unless (oref section hidden)
(dolist (child (oref section children))
(magit-diff-highlight-recursive child selection))))
(defun magit-diff-highlight-heading (section &optional selection)
(magit-section-make-overlay
(magit-section-start section)
(or (magit-section-content section)
(magit-section-end section))
(pcase (list (magit-section-type section)
(oref section start)
(or (oref section content)
(oref section end))
(pcase (list (oref section type)
(and (member section selection)
(not (eq this-command 'mouse-drag-region))))
(`(file t) 'magit-diff-file-heading-selection)
......@@ -2391,7 +2393,7 @@ are highlighted."
(unless magit-diff-highlight-hunk-body
(setq highlight nil))
(cond (highlight
(unless (magit-section-hidden section)
(unless (oref section hidden)
(add-to-list 'magit-section-highlighted-sections section)
(cond ((memq section magit-section-unhighlight-sections)
(setq magit-section-unhighlight-sections
......@@ -2399,7 +2401,7 @@ are highlighted."
(magit-diff-highlight-hunk-body
(setq paint t)))))
(t
(cond ((and (magit-section-hidden section)
(cond ((and (oref section hidden)
(memq section magit-section-unhighlight-sections))
(add-to-list 'magit-section-highlighted-sections section)
(setq magit-section-unhighlight-sections
......@@ -2408,8 +2410,8 @@ are highlighted."
(setq paint t)))))
(when paint
(save-excursion
(goto-char (magit-section-start section))
(let ((end (magit-section-end section))
(goto-char (oref section start))
(let ((end (oref section end))
(merging (looking-at "@@@"))
(stage nil)
(tab-width (magit-diff-tab-width
......@@ -2514,14 +2516,14 @@ are highlighted."
(defun magit-diff-update-hunk-refinement (&optional section)
(if section
(unless (magit-section-hidden section)
(unless (oref section hidden)
(pcase (list magit-diff-refine-hunk
(oref section refined)
(eq section (magit-current-section)))
((or `(all nil ,_) `(t nil t))
(oset section refined t)
(save-excursion
(goto-char (magit-section-start section))
(goto-char (oref section start))
;; `diff-refine-hunk' does not handle combined diffs.
(unless (looking-at "@@@")
;; Avoid fsyncing many small temp files
......@@ -2529,13 +2531,13 @@ are highlighted."
(diff-refine-hunk)))))
((or `(nil t ,_) `(t t nil))
(oset section refined nil)
(remove-overlays (magit-section-start section)
(magit-section-end section)
(remove-overlays (oref section start)
(oref section end)
'diff-mode 'fine))))
(cl-labels ((recurse (section)
(if (magit-section-match 'hunk section)
(magit-diff-update-hunk-refinement section)
(--each (magit-section-children section)
(--each (oref section children)
(recurse it)))))
(recurse magit-root-section))))
......@@ -2554,8 +2556,8 @@ are highlighted."
"Highlight the hunk-internal region if any."
(when (eq (magit-diff-scope section t) 'region)
(magit-diff--make-hunk-overlay
(magit-section-start section)
(1- (magit-section-content section))
(oref section start)
(1- (oref section content))
'face 'magit-diff-lines-heading
'display (magit-diff-hunk-region-header section)
'after-string (magit-diff--hunk-after-string 'magit-diff-lines-heading))
......@@ -2571,12 +2573,12 @@ for added and removed lines as for context lines."
'magit-diff-context)))
(when magit-diff-unmarked-lines-keep-foreground
(setq face (list :background (face-attribute face :background))))
(magit-diff--make-hunk-overlay (magit-section-content section)
(magit-diff--make-hunk-overlay (oref section content)
(magit-diff-hunk-region-beginning)
'face face
'priority 2)
(magit-diff--make-hunk-overlay (1+ (magit-diff-hunk-region-end))
(magit-section-end section)
(oref section end)
'face face
'priority 2)))
......@@ -2657,14 +2659,15 @@ https://github.com/magit/magit/pull/2293 for more details)."
(defun magit-diff-inside-hunk-body-p ()
"Return non-nil if point is inside the body of a hunk."
(and (magit-section-match 'hunk)
(> (point) (magit-section-content (magit-current-section)))))
(> (point)
(oref (magit-current-section) content))))
;;; Diff Extract
(defun magit-diff-file-header (section)
(when (eq (magit-section-type section) 'hunk)
(setq section (magit-section-parent section)))
(when (eq (magit-section-type section) 'file)
(when (eq (oref section type) 'hunk)
(setq section (oref section parent)))
(when (eq (oref section type) 'file)
(oref section header)))
(defun magit-diff-hunk-region-header (section)
......@@ -2674,10 +2677,10 @@ https://github.com/magit/magit/pull/2293 for more details)."
(defun magit-diff-hunk-region-patch (section &optional args)
(let ((op (if (member "--reverse" args) "+" "-"))
(sbeg (magit-section-start section))
(sbeg (oref section start))
(rbeg (magit-diff-hunk-region-beginning))
(rend (region-end))
(send (magit-section-end section))
(send (oref section end))
(patch nil))
(save-excursion
(goto-char sbeg)
......
......@@ -285,7 +285,7 @@ mind at all, then it asks the user for a command to run."
(interactive)
(magit-section-case
(hunk (save-excursion
(goto-char (magit-section-start (magit-section-parent it)))
(goto-char (oref (oref it parent) start))
(magit-ediff-dwim)))
(t
(let ((range (magit-diff--dwim))
......
......@@ -704,7 +704,7 @@ Sorted from longest to shortest CYGWIN name."
(defun magit-file-at-point ()
(magit-section-case
(file (magit-section-value it))
(file (oref it value))
(hunk (magit-section-parent-value it))))
(defun magit-current-file ()
......@@ -904,22 +904,22 @@ to, or to some other symbolic-ref that points to the same ref."
(defun magit-branch-at-point ()
(magit-section-case
(branch (magit-section-value it))
(commit (magit-name-branch (magit-section-value it)))))
(branch (oref it value))
(commit (magit-name-branch (oref it value)))))
(defun magit-local-branch-at-point ()
(magit-section-case
(branch (let ((branch (magit-ref-maybe-qualify (magit-section-value it))))
(branch (let ((branch (magit-ref-maybe-qualify (oref it value))))
(when (member branch (magit-list-local-branch-names))
branch)))
(commit (magit-name-local-branch (magit-section-value it)))))
(commit (magit-name-local-branch (oref it value)))))
(defun magit-remote-branch-at-point ()
(magit-section-case
(branch (let ((branch (magit-section-value it)))
(branch (let ((branch (oref it value)))
(when (member branch (magit-list-remote-branch-names))
branch)))
(commit (magit-name-remote-branch (magit-section-value it)))))
(commit (magit-name-remote-branch (oref it value)))))
(defun magit-commit-at-point ()
(or (magit-section-when commit)
......@@ -929,10 +929,10 @@ to, or to some other symbolic-ref that points to the same ref."
(defun magit-branch-or-commit-at-point ()
(or magit-buffer-refname
(magit-section-case
(branch (magit-ref-maybe-qualify (magit-section-value it)))
(commit (let ((rev (magit-section-value it)))
(branch (magit-ref-maybe-qualify (oref it value)))
(commit (let ((rev (oref it value)))
(or (magit-get-shortname rev) rev)))
(tag (magit-ref-maybe-qualify (magit-section-value it) "tags/")))
(tag (magit-ref-maybe-qualify (oref it value) "tags/")))
(thing-at-point 'git-revision t)
(and (derived-mode-p 'magit-revision-mode
'magit-merge-preview-mode)
......@@ -940,15 +940,15 @@ to, or to some other symbolic-ref that points to the same ref."
(defun magit-tag-at-point ()
(magit-section-case
(tag (magit-section-value it))
(commit (magit-name-tag (magit-section-value it)))))
(tag (oref it value))
(commit (magit-name-tag (oref it value)))))
(defun magit-stash-at-point ()
(magit-section-when stash))
(defun magit-remote-at-point ()
(magit-section-case
(remote (magit-section-value it))
(remote (oref it value))
(branch (magit-section-parent-value it))))
(defun magit-get-current-branch ()
......
......@@ -55,19 +55,19 @@ This function is used as a helper for functions set as
(while (magit-section--backward-find
(lambda ()
(let* ((section (magit-current-section))
(type (magit-section-type section))
(parent (magit-section-parent section))
(parent-type (magit-section-type parent)))
(type (oref section type))
(parent (oref section parent))
(parent-type (oref parent type)))
(and (-contains-p entry-types type)
(-contains-p menu-types parent-type)))))
(let* ((section (magit-current-section))
(name (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
(parent (magit-section-parent section))
(parent (oref section parent))
(parent-title (buffer-substring-no-properties
(magit-section-start parent)
(1- (magit-section-content parent)))))
(oref parent start)
(1- (oref parent content)))))
(puthash parent-title
(cons (cons name (point))
(gethash parent-title entries (list)))
......@@ -86,7 +86,7 @@ This function is used as a value for
(magit-section--backward-find
(lambda ()
(-contains-p '(commit stash)
(magit-section-type (magit-current-section))))))
(oref (magit-current-section) type)))))
;;;###autoload
(defun magit-imenu--log-extract-index-name-function ()
......@@ -109,10 +109,10 @@ This function is used as a value for
`imenu-prev-index-position-function'."
(magit-section--backward-find
(lambda ()
(and (equal (magit-section-type (magit-current-section)) 'file)
(not (equal (magit-section-type
(magit-section-parent (magit-current-section)))
'diffstat))))))
(let ((section (magit-current-section)))
(and (equal (oref section type) 'file)
(not (equal (oref (oref section parent) type)
'diffstat)))))))
;;;###autoload
(defun magit-imenu--diff-extract-index-name-function ()
......@@ -204,9 +204,7 @@ This function is used as a value for
`imenu-prev-index-position-function'."
(magit-section--backward-find
(lambda ()
(eq
(magit-section-type (magit-current-section))
'process))))
(eq (oref (magit-current-section) type) 'process))))
;;;###autoload
(defun magit-imenu--process-extract-index-name-function ()
......
......@@ -773,9 +773,9 @@ is displayed in the current frame."
(interactive "p")
(when (derived-mode-p 'magit-log-mode)
(magit-section-when commit
(let ((parent-rev (format "%s^%s" (magit-section-value it) (or n 1))))
(let ((parent-rev (format "%s^%s" (oref it value) (or n 1))))
(-if-let (parent-hash (magit-rev-parse "--short" parent-rev))
(-if-let (section (--first (equal (magit-section-value it)
(-if-let (section (--first (equal (oref it value)
parent-hash)