git-commit-vandalism/Documentation/technical
Ævar Arnfjörð Bjarmason 5cc044e025 get_short_oid: sort ambiguous objects by type, then SHA-1
Change the output emitted when an ambiguous object is encountered so
that we show tags first, then commits, followed by trees, and finally
blobs. Within each type we show objects in hashcmp() order. Before
this change the objects were only ordered by hashcmp().

The reason for doing this is that the output looks better as a result,
e.g. the v2.17.0 tag before this change on "git show e8f2" would
display:

    hint: The candidates are:
    hint:   e8f2093055 tree
    hint:   e8f21caf94 commit 2013-06-24 - bash prompt: print unique detached HEAD abbreviated object name
    hint:   e8f21d02f7 blob
    hint:   e8f21d577c blob
    hint:   e8f25a3a50 tree
    hint:   e8f26250fa commit 2017-02-03 - Merge pull request #996 from jeffhostetler/jeffhostetler/register_rename_src
    hint:   e8f2650052 tag v2.17.0
    hint:   e8f2867228 blob
    hint:   e8f28d537c tree
    hint:   e8f2a35526 blob
    hint:   e8f2bc0c06 commit 2015-05-10 - Documentation: note behavior for multiple remote.url entries
    hint:   e8f2cf6ec0 tree

Now we'll instead show:

    hint:   e8f2650052 tag v2.17.0
    hint:   e8f21caf94 commit 2013-06-24 - bash prompt: print unique detached HEAD abbreviated object name
    hint:   e8f26250fa commit 2017-02-03 - Merge pull request #996 from jeffhostetler/jeffhostetler/register_rename_src
    hint:   e8f2bc0c06 commit 2015-05-10 - Documentation: note behavior for multiple remote.url entries
    hint:   e8f2093055 tree
    hint:   e8f25a3a50 tree
    hint:   e8f28d537c tree
    hint:   e8f2cf6ec0 tree
    hint:   e8f21d02f7 blob
    hint:   e8f21d577c blob
    hint:   e8f2867228 blob
    hint:   e8f2a35526 blob

Since we show the commit data in the output that's nicely aligned once
we sort by object type. The decision to show tags before commits is
pretty arbitrary. I don't want to order by object_type since there
tags come last after blobs, which doesn't make sense if we want to
show the most important things first.

I could display them after commits, but it's much less likely that
we'll display a tag, so if there is one it makes sense to show it
prominently at the top.

A note on the implementation: Derrick rightly pointed out[1] that
we're bending over backwards here in get_short_oid() to first
de-duplicate the list, and then emit it, but could simply do it in one
step.

The reason for that is that oid_array_for_each_unique() doesn't
actually require that the array be sorted by oid_array_sort(), it just
needs to be sorted in some order that guarantees that all objects with
the same ID are adjacent to one another, which (barring a hash
collision, which'll be someone else's problem) the sort_ambiguous()
function does.

I agree that would be simpler for this code, and had forgotten why I
initially wrote it like this[2]. But on further reflection I think
it's better to do more work here just so we're not underhandedly using
the oid-array API where we lie about the list being sorted. That would
break any subsequent use of oid_array_lookup() in subtle ways.

I could get around that by hacking the API itself to support this
use-case and documenting it, which I did as a WIP patch in [3], but I
think it's too much code smell just for this one call site. It's
simpler for the API to just introduce a oid_array_for_each() function
to eagerly spew out the list without sorting or de-duplication, and
then do the de-duplication and sorting in two passes.

1. https://public-inbox.org/git/20180501130318.58251-1-dstolee@microsoft.com/
2. https://public-inbox.org/git/876047ze9v.fsf@evledraar.gmail.com/
3. https://public-inbox.org/git/874ljrzctc.fsf@evledraar.gmail.com/

Helped-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-05-11 14:43:23 +09:00
..
.gitignore
api-allocation-growing.txt
api-argv-array.txt api-argv-array.txt: remove broken link to string-list API 2017-10-06 21:16:03 +09:00
api-config.txt config: remove git_config_maybe_bool 2017-09-07 09:48:20 +09:00
api-credentials.txt Documentation: fix linkgit references 2016-05-09 15:44:14 -07:00
api-diff.txt
api-directory-listing.txt Documentation: fix several one-character-off spelling errors 2018-04-09 14:15:02 +09:00
api-error-handling.txt
api-gitattributes.txt attr: retire git_check_attrs() API 2017-02-01 13:46:52 -08:00
api-grep.txt
api-history-graph.txt
api-index-skel.txt
api-index.sh
api-merge.txt
api-object-access.txt sha1_file.c: rename to use dash in file name 2018-04-11 18:11:00 +09:00
api-oid-array.txt get_short_oid: sort ambiguous objects by type, then SHA-1 2018-05-11 14:43:23 +09:00
api-parse-options.txt timestamp_t: a new data type for timestamps 2017-04-27 13:07:39 +09:00
api-quote.txt
api-ref-iteration.txt refs: remove dead for_each_*_submodule() 2017-08-24 14:56:28 -07:00
api-remote.txt http: allow selection of proxy authentication method 2016-01-26 10:53:09 -08:00
api-revision-walking.txt
api-run-command.txt run-command: factor out child_process_clear() 2015-11-02 15:01:00 -08:00
api-setup.txt pathspec: remove the deprecated get_pathspec function 2017-01-08 18:04:17 -08:00
api-sigchain.txt
api-submodule-config.txt Correct mispellings of ".gitmodule" to ".gitmodules" 2018-02-14 11:34:34 -08:00
api-trace.txt Merge branch 'ep/trace-doc-sample-fix' into maint 2016-04-29 14:16:00 -07:00
api-tree-walking.txt tree-walk: convert fill_tree_descriptor() to object_id 2017-08-14 12:38:54 -07:00
api-xdiff-interface.txt
bitmap-format.txt
hash-function-transition.txt doc hash-function-transition: clarify what SHAttered means 2018-03-27 19:08:31 -07:00
http-protocol.txt smart-http: document flush after "# service" line 2018-03-05 11:05:19 -08:00
index-format.txt fsmonitor: add documentation for the fsmonitor extension. 2017-10-01 17:23:05 +09:00
long-running-process-protocol.txt Docs: split out long-running subprocess handshake 2018-01-25 11:24:32 -08:00
pack-format.txt
pack-heuristics.txt
pack-protocol.txt Merge branch 'jh/partial-clone' 2018-02-13 13:39:04 -08:00
partial-clone.txt partial-clone: design doc 2017-12-14 13:10:57 -08:00
protocol-capabilities.txt upload-pack: add object filtering for partial clone 2017-12-08 09:58:51 -08:00
protocol-common.txt Merge branch 'ls/packet-line-protocol-doc-fix' 2016-08-31 10:03:51 -07:00
racy-git.txt Makefile / racy-git.txt: clarify USE_NSEC prerequisites 2015-07-01 14:54:42 -07:00
repository-version.txt extension.partialclone: introduce partial clone extension 2017-12-05 09:46:05 -08:00
send-pack-pipeline.txt
shallow.txt
signature-format.txt Documentation/technical: signed merge tag format 2016-06-17 12:10:48 -07:00
trivial-merge.txt treewide: correct several "up-to-date" to "up to date" 2017-08-23 12:17:22 -07:00