1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-11 10:28:26 +02:00
git/builtin
Victoria Dye 56d26ade97 ref-filter.c: really don't sort when using --no-sort
When '--no-sort' is passed to 'for-each-ref', 'tag', and 'branch', the
printed refs are still sorted by ascending refname. Change the handling of
sort options in these commands so that '--no-sort' to truly disables
sorting.

'--no-sort' does not disable sorting in these commands is because their
option parsing does not distinguish between "the absence of '--sort'"
(and/or values for tag.sort & branch.sort) and '--no-sort'. Both result in
an empty 'sorting_options' string list, which is parsed by
'ref_sorting_options()' to create the 'struct ref_sorting *' for the
command. If the string list is empty, 'ref_sorting_options()' interprets
that as "the absence of '--sort'" and returns the default ref sorting
structure (equivalent to "refname" sort).

To handle '--no-sort' properly while preserving the "refname" sort in the
"absence of --sort'" case, first explicitly add "refname" to the string list
*before* parsing options. This alone doesn't actually change any behavior,
since 'compare_refs()' already falls back on comparing refnames if two refs
are equal w.r.t all other sort keys.

Now that the string list is populated by default, '--no-sort' is the only
way to empty the 'sorting_options' string list. Update
'ref_sorting_options()' to return a NULL 'struct ref_sorting *' if the
string list is empty, and add a condition to 'ref_array_sort()' to skip the
sort altogether if the sort structure is NULL. Note that other functions
using 'struct ref_sorting *' do not need any changes because they already
ignore NULL values.

Finally, remove the condition around sorting in 'ls-remote', since it's no
longer necessary. Unlike 'for-each-ref' et. al., it does *not* do any
sorting by default. This default is preserved by simply leaving its sort key
string list empty before parsing options; if no additional sort keys are
set, 'struct ref_sorting *' is NULL and sorting is skipped.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-11-16 14:02:58 +09:00
..
add.c Merge branch 'ni/die-message-fix-for-git-add' into maint-2.42 2023-11-02 16:53:27 +09:00
am.c Merge branch 'ob/am-msgfix' into maint-2.42 2023-11-02 16:53:25 +09:00
annotate.c
apply.c
archive.c
bisect.c
blame.c
branch.c ref-filter.c: really don't sort when using --no-sort 2023-11-16 14:02:58 +09:00
bugreport.c
bundle.c
cat-file.c
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout--worker.c
checkout-index.c
checkout.c
clean.c
clone.c
column.c
commit-graph.c
commit-tree.c
commit.c Merge branch 'jc/commit-new-underscore-index-fix' into maint-2.42 2023-11-02 16:53:28 +09:00
config.c
count-objects.c
credential-cache--daemon.c
credential-cache.c
credential-store.c
credential.c
describe.c
diagnose.c
diff-files.c
diff-index.c
diff-tree.c
diff.c
difftool.c
fast-export.c
fast-import.c
fetch-pack.c
fetch.c
fmt-merge-msg.c
for-each-ref.c ref-filter.c: really don't sort when using --no-sort 2023-11-16 14:02:58 +09:00
for-each-repo.c
fsck.c
fsmonitor--daemon.c
gc.c
get-tar-commit-id.c
grep.c Merge branch 'rs/grep-parseopt-simplify' into maint-2.42 2023-11-02 16:53:24 +09:00
hash-object.c
help.c
hook.c
index-pack.c
init-db.c
interpret-trailers.c
log.c
ls-files.c
ls-remote.c ref-filter.c: really don't sort when using --no-sort 2023-11-16 14:02:58 +09:00
ls-tree.c
mailinfo.c
mailsplit.c
merge-base.c
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c
merge.c
mktag.c
mktree.c
multi-pack-index.c
mv.c Merge branch 'jc/mv-d-to-d-error-message-fix' into maint-2.42 2023-11-02 16:53:22 +09:00
name-rev.c
notes.c
pack-objects.c
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c
prune.c
pull.c
push.c
range-diff.c
read-tree.c
rebase.c
receive-pack.c Merge branch 'ts/unpacklimit-config-fix' into maint-2.42 2023-11-02 16:53:16 +09:00
reflog.c
remote-ext.c
remote-fd.c
remote.c
repack.c
replace.c
rerere.c
reset.c
rev-list.c
rev-parse.c
revert.c
rm.c
send-pack.c
shortlog.c
show-branch.c
show-index.c
show-ref.c
sparse-checkout.c
stash.c
stripspace.c
submodule--helper.c
symbolic-ref.c
tag.c ref-filter.c: really don't sort when using --no-sort 2023-11-16 14:02:58 +09:00
unpack-file.c
unpack-objects.c
update-index.c
update-ref.c
update-server-info.c
upload-archive.c
upload-pack.c
var.c Merge branch 'bc/more-git-var' into maint-2.42 2023-11-02 16:53:23 +09:00
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c Merge branch 'ja/worktree-orphan' into maint-2.42 2023-11-02 16:53:21 +09:00
write-tree.c