From 03df6cb833a21e924b02af58df76d93a8e0d9648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:33 +0100 Subject: reflog.c: indent argument lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reflog.c was lib-ified in 7d3d226e700 (reflog: libify delete reflog function and helpers, 2022-03-02) these previously "static" functions were made non-"static", but the argument lists were not correspondingly indented according to our usual coding style. Let's do that. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- reflog.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/reflog.c b/reflog.c index 333fd8708f..82e5a93511 100644 --- a/reflog.c +++ b/reflog.c @@ -240,8 +240,8 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit * Return true iff the specified reflog entry should be expired. */ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid, - const char *email, timestamp_t timestamp, int tz, - const char *message, void *cb_data) + const char *email, timestamp_t timestamp, int tz, + const char *message, void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; struct commit *old_commit, *new_commit; @@ -273,10 +273,10 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid, } int should_expire_reflog_ent_verbose(struct object_id *ooid, - struct object_id *noid, - const char *email, - timestamp_t timestamp, int tz, - const char *message, void *cb_data) + struct object_id *noid, + const char *email, + timestamp_t timestamp, int tz, + const char *message, void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; int expire; @@ -323,8 +323,8 @@ static int is_head(const char *refname) } void reflog_expiry_prepare(const char *refname, - const struct object_id *oid, - void *cb_data) + const struct object_id *oid, + void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; struct commit_list *elem; @@ -377,8 +377,8 @@ void reflog_expiry_cleanup(void *cb_data) } int count_reflog_ent(struct object_id *ooid, struct object_id *noid, - const char *email, timestamp_t timestamp, int tz, - const char *message, void *cb_data) + const char *email, timestamp_t timestamp, int tz, + const char *message, void *cb_data) { struct cmd_reflog_expire_cb *cb = cb_data; if (!cb->expire_total || timestamp < cb->expire_total) -- cgit v1.2.3 From 5f9b64a6c26552af2c3c57ea37f308537dc5bee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:34 +0100 Subject: reflog: refactor cmd_reflog() to "if" branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the "if" branches in cmd_reflog() to use "else if" instead, and remove the whitespace between them. As with 92f480909f7 (multi-pack-index: refactor "goto usage" pattern, 2021-08-23) this makes this code more consistent with how builtin/{bundle,stash,commit-graph,multi-pack-index}.c look and behave. Their top-level commands are all similar sub-command routing functions. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/reflog.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 9407f835cb..c864f27630 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -384,14 +384,11 @@ int cmd_reflog(int argc, const char **argv, const char *prefix) if (!strcmp(argv[1], "show")) return cmd_log_reflog(argc - 1, argv + 1, prefix); - - if (!strcmp(argv[1], "expire")) + else if (!strcmp(argv[1], "expire")) return cmd_reflog_expire(argc - 1, argv + 1, prefix); - - if (!strcmp(argv[1], "delete")) + else if (!strcmp(argv[1], "delete")) return cmd_reflog_delete(argc - 1, argv + 1, prefix); - - if (!strcmp(argv[1], "exists")) + else if (!strcmp(argv[1], "exists")) return cmd_reflog_exists(argc - 1, argv + 1, prefix); return cmd_log_reflog(argc, argv, prefix); -- cgit v1.2.3 From d3ab1a5fcf3db26ba36fb5be07365908f7906ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:35 +0100 Subject: reflog tests: add missing "git reflog exists" tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There were a few "git reflog exists" tests scattered over the test suite, but let's consolidate the testing of the main functionality into a new test file. This makes it easier to run just these tests during development. To do that amend and extend an existing test added in afcb2e7a3b8 (git-reflog: add exists command, 2015-07-21). Let's use "test_must_fail" instead of "!" (in case it segfaults), and test for basic usage, an unknown option etc. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 5 ----- t/t1418-reflog-exists.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 t/t1418-reflog-exists.sh diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 0bb319b944..975c4ea83a 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -169,9 +169,4 @@ test_expect_success 'git log -g -p shows diffs vs. parents' ' test_cmp expect actual ' -test_expect_success 'reflog exists works' ' - git reflog exists refs/heads/main && - ! git reflog exists refs/heads/nonexistent -' - test_done diff --git a/t/t1418-reflog-exists.sh b/t/t1418-reflog-exists.sh new file mode 100755 index 0000000000..60c6411ce3 --- /dev/null +++ b/t/t1418-reflog-exists.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='Test reflog display routines' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit A +' + +test_expect_success 'usage' ' + test_expect_code 129 git reflog exists && + test_expect_code 129 git reflog exists -h +' + +test_expect_success 'usage: unknown option' ' + test_expect_code 129 git reflog exists --unknown-option +' + +test_expect_success 'reflog exists works' ' + git reflog exists refs/heads/main && + test_must_fail git reflog exists refs/heads/nonexistent +' + +test_expect_success 'reflog exists works with a "--" delimiter' ' + git reflog exists -- refs/heads/main && + test_must_fail git reflog exists -- refs/heads/nonexistent +' + +test_done -- cgit v1.2.3 From 1e91d3faf6c6de7667603c9c81252161ee70d7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:36 +0100 Subject: reflog: move "usage" variables and use macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the "usage" variables in builtin/reflog.c to the top of the file, in preparation for later commits defining a common "reflog_usage" in terms of some of these strings, as was done in 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23). While we're at it let's make them "const char *const", as is the convention with these "usage" variables. The use of macros here is a bit odd, but in subsequent commits we'll make these use the same pattern as builtin/commit-graph.c uses since 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23). Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/reflog.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index c864f27630..25313d504a 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -5,8 +5,31 @@ #include "worktree.h" #include "reflog.h" +#define BUILTIN_REFLOG_EXPIRE_USAGE \ + N_("git reflog expire [--expire=