gitk: Add a "Copy commit summary" command
authorBeat Bolli <dev+git@drbeat.li>
Sat, 18 Jul 2015 11:15:39 +0000 (13:15 +0200)
committerPaul Mackerras <paulus@samba.org>
Thu, 13 Aug 2015 03:47:43 +0000 (13:47 +1000)
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>
Signed-off-by: Paul Mackerras <paulus@samba.org>
gitk
diff --git a/gitk b/gitk
index 2cb12bd7a80634d5811dbbc53d240bf98d036595..51520effbe87bf34b407d6a41ff4ddde7cdbd7c3 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -2618,6 +2618,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}
@@ -9360,6 +9361,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