public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Beat Bolli <dev+git@drbeat•li>
To: git@vger•kernel.org
Cc: Beat Bolli <dev+git@drbeat•li>, Paul Mackerras <paulus@samba•org>
Subject: [PATCH v4] gitk: Add a "Copy commit summary" command
Date: Sat, 18 Jul 2015 13:15:39 +0200	[thread overview]
Message-ID: <1437218139-7031-1-git-send-email-dev+git@drbeat.li> (raw)

When referring to earlier commits in commit messages or other text, one
of the established formats is

    <abbrev-sha> ("<summary>", <author-date>)

Add a "Copy commit summary" command to the context menu that puts this
text for the currently selected commit on the clipboard. This makes it
easy for our users to create well-formatted commit references.

The <abbrev-sha> is produced with the %h format specifier to make it
unique. Its length can be controlled with the gitk preference
"Auto-select SHA1 (length)", or, if this preference is set to its
default value (40), with the Git config setting core.abbrev.

Signed-off-by: Beat Bolli <dev+git@drbeat•li>
Cc: Paul Mackerras <paulus@samba•org>
---
Changes since v3:
- consider $autosellen for the --abbrev value

Changes since v2:
- call git show to produce a unique <abbrev-sha>
- use the short date format

Changes since v1:
- drop the "commit " literal in front of the <abbrev-sha>

Signed-off-by: Beat Bolli <dev+git@drbeat•li>
---
 gitk-git/gitk | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 9a2daf3..d05169a 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -2617,6 +2617,7 @@ proc makewindow {} {
 	{mc "Diff selected -> this" command {diffvssel 1}}
 	{mc "Make patch" command mkpatch}
 	{mc "Create tag" command mktag}
+	{mc "Copy commit summary" command copysummary}
 	{mc "Write commit to file" command writecommit}
 	{mc "Create new branch" command mkbranch}
 	{mc "Cherry-pick this commit" command cherrypick}
@@ -9341,6 +9342,20 @@ proc mktaggo {} {
     mktagcan
 }
 
+proc copysummary {} {
+    global rowmenuid autosellen
+
+    set format "%h (\"%s\", %ad)"
+    set cmd [list git show -s --pretty=format:$format --date=short]
+    if {$autosellen < 40} {
+        lappend cmd --abbrev=$autosellen
+    }
+    set summary [eval exec $cmd $rowmenuid]
+
+    clipboard clear
+    clipboard append $summary
+}
+
 proc writecommit {} {
     global rowmenuid wrcomtop commitinfo wrcomcmd NS
 
-- 
2.1.4

             reply	other threads:[~2015-07-18 11:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-18 11:15 Beat Bolli [this message]
2015-07-21 10:19 ` [PATCH v4] gitk: Add a "Copy commit summary" command Beat Bolli
2015-07-21 10:28   ` Paul Mackerras
2015-07-21 10:30     ` Beat Bolli
2015-08-11 21:00 ` [PATCH] gitk: adjust the menu line numbers to compensate for the new entry Beat Bolli
2015-08-13  7:37 ` [PATCH v4] gitk: Add a "Copy commit summary" command Paul Mackerras
2015-08-13 19:02   ` Beat Bolli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437218139-7031-1-git-send-email-dev+git@drbeat.li \
    --to=dev+git@drbeat$(echo .)li \
    --cc=git@vger$(echo .)kernel.org \
    --cc=paulus@samba$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox