Skip to content

Commit

Permalink
magit-copy-revision-abbreviated: New option
Browse files Browse the repository at this point in the history
magit-copy-buffer-revision, and magit-copy-section-value when
appropriate, pushes the full revision hash to magit-revision-stack and
the kill ring.  If callers would like to use this to insert an
abbreviated hash, their main options are either to
(1) yank the full hash and truncate it manually or (2) configure
magit-pop-revision-stack-format accordingly and call
magit-pop-revision-stack.

Offer an option to put the abbreviated hash on the kill ring and the
magit-revision-stack.
  • Loading branch information
magnusmalm authored and kyleam committed Dec 23, 2019
1 parent 1e3215f commit d1d8e49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Documentation/RelNotes/2.91.0.org
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@
- Commands under the ~magit-gitignore~ prefix now include directories
that contain only untracked files as completion candidates. #3985

- Added new option ~magit-copy-revision-abbreviated~. #4014

** Fixes since v2.90.0

- Bumped the minimal required version of ~git-commit~ to the correct
Expand Down
24 changes: 21 additions & 3 deletions lisp/magit-extras.el
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ that)."
(choice (regexp :tag "Find index regexp")
(const :tag "Don't number entries" nil))))

(defcustom magit-copy-revision-abbreviated nil
"Whether to save abbreviated revision to `kill-ring' and `magit-revision-stack'."
:package-version '(magit . "2.91.0")
:group 'magit-miscellaneous
:type 'boolean)

;;;###autoload
(defun magit-pop-revision-stack (rev toplevel)
"Insert a representation of a revision into the current buffer.
Expand Down Expand Up @@ -552,6 +558,10 @@ the current section is a commit, branch, or tag section, push
the (referenced) revision to the `magit-revision-stack' for use
with `magit-pop-revision-stack'.
When `magit-copy-revision-abbreviated' is non-nil, save the
abbreviated revision to the `kill-ring' and the
`magit-revision-stack'.
When the current section is a branch or a tag, and a prefix
argument is used, then save the revision at its tip to the
`kill-ring' instead of the reference name.
Expand Down Expand Up @@ -586,7 +596,9 @@ hunk, strip the outer diff marker column."
(file-name-as-directory
(expand-file-name (magit-section-parent-value section)
(magit-toplevel))))))
(setq value (magit-rev-parse value))
(setq value (magit-rev-parse
(and magit-copy-revision-abbreviated "--short")
value))
(push (list value default-directory) magit-revision-stack)
(kill-new (message "%s" (or (and current-prefix-arg ref)
value)))))
Expand All @@ -613,7 +625,11 @@ the current section instead, using `magit-copy-section-value'.
When the region is active, then save that to the `kill-ring',
like `kill-ring-save' would, instead of behaving as described
above."
above.
When `magit-copy-revision-abbreviated' is non-nil, save the
abbreviated revision to the `kill-ring' and the
`magit-revision-stack'."
(interactive)
(if (use-region-p)
(call-interactively #'copy-region-as-kill)
Expand All @@ -626,7 +642,9 @@ above."
magit-buffer-range))
(magit-status-mode "HEAD")))))
(when (magit-commit-p rev)
(setq rev (magit-rev-parse rev))
(setq rev (magit-rev-parse
(and magit-copy-revision-abbreviated "--short")
rev))
(push (list rev default-directory) magit-revision-stack)
(kill-new (message "%s" rev))))))

Expand Down

0 comments on commit d1d8e49

Please sign in to comment.