diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-10-10 12:42:58 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-10-11 15:01:37 +0900 |
commit | be26d2b29b6a58fc53ed9d38c3f36b195f8a7cc9 (patch) | |
tree | e8875d8ec57b73010cabbe1c2b39e5eca4740559 /t/t4126-apply-empty.sh | |
parent | Git 2.14.2 (diff) | |
download | tgif-be26d2b29b6a58fc53ed9d38c3f36b195f8a7cc9.tar.xz |
describe: do not use cmd_*() as a subroutine
The cmd_foo() function is a moral equivalent of 'main' for a Git
subcommand 'git foo', and as such, it is allowed to do many things
that make it unsuitable to be called as a subroutine, including
- call exit(3) to terminate the process;
- allocate resource held and used throughout its lifetime, without
releasing it upon return/exit;
- rely on global variables being initialized at program startup,
and update them as needed, making another clean invocation of the
function impossible.
The call to cmd_diff_index() "git describe" makes has been working
by accident that the function did not call exit(3); it sets a bad
precedent for people to cut and paste.
We could invoke it via the run_command() interface, but the diff
family of commands have helper functions in diff-lib.c that are
meant to be usable as subroutines, and using the latter does not
make the resulting code all that longer. Use it.
Note that there is also an invocation of cmd_name_rev() at the end;
"git describe --contains" massages its command line arguments to be
suitable for "git name-rev" invocation and jumps to it, never to
regain control. This call is left as-is as an exception to the
rule. When we start to allow calling name-rev repeatedly as a
helper function, we would be able to remove this call as well.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4126-apply-empty.sh')
0 files changed, 0 insertions, 0 deletions