git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] gitk: Add a "Copy commit summary" command

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 16, 2015, 17:02 UTC
Message-ID
<xmqq380o593i.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1437060565-4716-1-git-send-email-dev+git@drbeat.li>
Beat Bolli <dev+git@drbeat.li> writes:
Show 11 quoted lines
> When referring to earlier commits in commit messages or other text, one
> of the established formats is
>
>     <abbrev-sha> ("<summary>", <author-date>)
> ...
> +proc copysummary {} {
> +    global rowmenuid commitinfo
> +
> +    set id [string range $rowmenuid 0 7]
> +    set info $commitinfo($rowmenuid)
> +    set commit [lindex $info 0]

7 hexdigits is not always an appropriate value for all projects. The minimum necessary to guarantee uniqueness varies on project, and it is not a good idea to hardcode such a small value. Not-so-old Linux kernel history seems to use at least 12, for example.

I believe that the "one of the established formats" comes from a "git one" alias I published somewhere long time ago, that did something like this:

  git show -s --abbrev=8 --pretty='format:%h (%s, %ai' "$@" |
  sed -e 's/ [012][0-9]:[0-5][0-9]:[0-5][0-9] [-+][0-9][0-9][0-9][0-9]$/)/'

where the combination of --abbrev=8 and format:%h asks for a unique abbreviation that is at least 8 hexdigits long but can use more than 8 if it is not long enough to uniquely identify the given commit.

I do not offhand know how $commitinfo is populated, but perhaps you can tweak that code to ask for both %H (for the full commit object ID) and %h (for the unique abbreviation of appropriate length) and store the value for %h to a new field in the $commitinfo($rowmenuid) array, so that you do not have to have such a hard-coded truncation here?

Show 9 quoted lines
> +    set date [formatdate [lindex $info 2]]
> +    set summary "$id (\"$commit\", $date)"
> +
> +    clipboard clear
> +    clipboard append $summary
> +}
> +
>  proc writecommit {} {
>      global rowmenuid wrcomtop commitinfo wrcomcmd NS
Previous: Beat BolliNext: Stefan Haller
Message 2 of 9 in “gitk: Add a "Copy commit summary" command”
  1. gitk: Add a "Copy commit summary" commandBeat Bolli, Jul 16, 2015
  2. Junio C HamanoJul 16, 2015
  3. Stefan HallerJul 17, 2015
  4. Beat BolliJul 17, 2015
  5. Johannes SixtJul 16, 2015
  6. Paul MackerrasJul 17, 2015
  7. Junio C HamanoJul 17, 2015
  8. Paul MackerrasJul 18, 2015
  9. Beat BolliJul 18, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.