From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Han-Wen Nienhuys" <hanwen@google.com>,
"Bagas Sanjaya" <bagasdotme@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 09/12] reflog + refs-backend: move "verbose" out of the backend
Date: Tue, 30 Nov 2021 22:38:11 +0100 [thread overview]
Message-ID: <patch-09.12-6a8f3915898-20211130T213319Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.12-00000000000-20211130T213319Z-avarab@gmail.com>
Move the handling of the "verbose" flag entirely out of
"refs/files-backend.c" and into "builtin/reflog.c". This allows the
backend to stop knowing about the EXPIRE_REFLOGS_VERBOSE flag.
The expire_reflog_ent() function shouldn't need to deal with the
implementation detail of whether or not we're emitting verbose output,
by doing this the --verbose output becomes backend-agnostic, so
reftable will get the same output.
I think the output is rather bad currently, and should e.g. be
implemented with some better future mode of progress.[ch], but that's
a topic for another improvement.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
builtin/reflog.c | 42 +++++++++++++++++++++++++++++++-----------
refs.h | 3 +--
refs/files-backend.c | 44 ++++++++++++++++++++------------------------
3 files changed, 52 insertions(+), 37 deletions(-)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 48e4f5887b0..a77c0d96dce 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -45,6 +45,8 @@ struct expire_reflog_policy_cb {
struct cmd_reflog_expire_cb cmd;
struct commit *tip_commit;
struct commit_list *tips;
+ unsigned int dry_run:1,
+ verbose:1;
};
struct worktree_reflogs {
@@ -294,29 +296,38 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no
struct commit *old_commit, *new_commit;
if (timestamp < cb->cmd.expire_total)
- return 1;
+ goto expire;
old_commit = new_commit = NULL;
if (cb->cmd.stalefix &&
(!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
- return 1;
+ goto expire;
if (timestamp < cb->cmd.expire_unreachable) {
switch (cb->unreachable_expire_kind) {
case UE_ALWAYS:
- return 1;
+ goto expire;
case UE_NORMAL:
case UE_HEAD:
if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid))
- return 1;
+ goto expire;
break;
}
}
if (cb->cmd.recno && --(cb->cmd.recno) == 0)
- return 1;
+ goto expire;
+
+ if (cb->verbose)
+ printf("keep %s", message);
return 0;
+expire:
+ if (cb->dry_run)
+ printf("would prune %s", message);
+ else if (cb->verbose)
+ printf("prune %s", message);
+ return 1;
}
static int push_tip_to_list(const char *refname, const struct object_id *oid,
@@ -539,6 +550,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
int i, status, do_all, all_worktrees = 1;
int explicit_expiry = 0;
unsigned int flags = 0;
+ int verbose = 0;
default_reflog_expire_unreachable = now - 30 * 24 * 3600;
default_reflog_expire = now - 90 * 24 * 3600;
@@ -576,7 +588,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
else if (!strcmp(arg, "--single-worktree"))
all_worktrees = 0;
else if (!strcmp(arg, "--verbose"))
- flags |= EXPIRE_REFLOGS_VERBOSE;
+ verbose = 1;
else if (!strcmp(arg, "--")) {
i++;
break;
@@ -599,10 +611,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
revs.do_not_die_on_missing_tree = 1;
revs.ignore_missing = 1;
revs.ignore_missing_links = 1;
- if (flags & EXPIRE_REFLOGS_VERBOSE)
+ if (verbose)
printf(_("Marking reachable objects..."));
mark_reachable_objects(&revs, 0, 0, NULL);
- if (flags & EXPIRE_REFLOGS_VERBOSE)
+ if (verbose)
putchar('\n');
}
@@ -624,7 +636,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
free_worktrees(worktrees);
for_each_string_list_item(item, &collected.reflogs) {
- struct expire_reflog_policy_cb cb = { .cmd = cmd };
+ struct expire_reflog_policy_cb cb = {
+ .cmd = cmd,
+ .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
+ .verbose = verbose,
+ };
set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string);
status |= reflog_expire(item->string, flags,
@@ -671,6 +687,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
struct cmd_reflog_expire_cb cmd = { 0 };
int i, status = 0;
unsigned int flags = 0;
+ int verbose = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
@@ -681,7 +698,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
else if (!strcmp(arg, "--updateref"))
flags |= EXPIRE_REFLOGS_UPDATE_REF;
else if (!strcmp(arg, "--verbose"))
- flags |= EXPIRE_REFLOGS_VERBOSE;
+ verbose = 1;
else if (!strcmp(arg, "--")) {
i++;
break;
@@ -699,7 +716,10 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
const char *spec = strstr(argv[i], "@{");
char *ep, *ref;
int recno;
- struct expire_reflog_policy_cb cb = { 0 };
+ struct expire_reflog_policy_cb cb = {
+ .verbose = verbose,
+ .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
+ };
if (!spec) {
status |= error(_("not a reflog: %s"), argv[i]);
diff --git a/refs.h b/refs.h
index 45c34e99e3a..0c3374b405c 100644
--- a/refs.h
+++ b/refs.h
@@ -786,8 +786,7 @@ enum ref_type ref_type(const char *refname);
enum expire_reflog_flags {
EXPIRE_REFLOGS_DRY_RUN = 1 << 0,
EXPIRE_REFLOGS_UPDATE_REF = 1 << 1,
- EXPIRE_REFLOGS_VERBOSE = 1 << 2,
- EXPIRE_REFLOGS_REWRITE = 1 << 3
+ EXPIRE_REFLOGS_REWRITE = 1 << 2,
};
/*
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 451c4e2a052..c154c3c4a23 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3080,11 +3080,12 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
}
struct expire_reflog_cb {
- unsigned int flags;
reflog_expiry_should_prune_fn *should_prune_fn;
void *policy_cb;
FILE *newlog;
struct object_id last_kept_oid;
+ unsigned int rewrite:1,
+ dry_run:1;
};
static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
@@ -3092,33 +3093,27 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *message, void *cb_data)
{
struct expire_reflog_cb *cb = cb_data;
- struct expire_reflog_policy_cb *policy_cb = cb->policy_cb;
+ reflog_expiry_should_prune_fn *fn = cb->should_prune_fn;
- if (cb->flags & EXPIRE_REFLOGS_REWRITE)
+ if (cb->rewrite)
ooid = &cb->last_kept_oid;
- if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz,
- message, policy_cb)) {
- if (cb->flags & EXPIRE_REFLOGS_DRY_RUN)
- printf("would prune %s", message);
- else if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
- printf("prune %s", message);
- } else {
- if (!(cb->flags & EXPIRE_REFLOGS_DRY_RUN)) {
- fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s",
- oid_to_hex(ooid), oid_to_hex(noid),
- email, timestamp, tz, message);
- oidcpy(&cb->last_kept_oid, noid);
- }
- if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
- printf("keep %s", message);
- }
+ if (fn(ooid, noid, email, timestamp, tz, message, cb->policy_cb))
+ return 0;
+
+ if (cb->dry_run)
+ return 0; /* --dry-run */
+
+ fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", oid_to_hex(ooid),
+ oid_to_hex(noid), email, timestamp, tz, message);
+ oidcpy(&cb->last_kept_oid, noid);
+
return 0;
}
static int files_reflog_expire(struct ref_store *ref_store,
const char *refname,
- unsigned int flags,
+ unsigned int expire_flags,
reflog_expiry_prepare_fn prepare_fn,
reflog_expiry_should_prune_fn should_prune_fn,
reflog_expiry_cleanup_fn cleanup_fn,
@@ -3136,7 +3131,8 @@ static int files_reflog_expire(struct ref_store *ref_store,
const struct object_id *oid;
memset(&cb, 0, sizeof(cb));
- cb.flags = flags;
+ cb.rewrite = !!(expire_flags & EXPIRE_REFLOGS_REWRITE);
+ cb.dry_run = !!(expire_flags & EXPIRE_REFLOGS_DRY_RUN);
cb.policy_cb = policy_cb_data;
cb.should_prune_fn = should_prune_fn;
@@ -3172,7 +3168,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
files_reflog_path(refs, &log_file_sb, refname);
log_file = strbuf_detach(&log_file_sb, NULL);
- if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
+ if (!cb.dry_run) {
/*
* Even though holding $GIT_DIR/logs/$reflog.lock has
* no locking implications, we use the lock_file
@@ -3199,7 +3195,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
(*cleanup_fn)(cb.policy_cb);
- if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
+ if (!cb.dry_run) {
/*
* It doesn't make sense to adjust a reference pointed
* to by a symbolic ref based on expiring entries in
@@ -3209,7 +3205,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
*/
int update = 0;
- if ((flags & EXPIRE_REFLOGS_UPDATE_REF) &&
+ if ((expire_flags & EXPIRE_REFLOGS_UPDATE_REF) &&
!is_null_oid(&cb.last_kept_oid)) {
int ignore_errno;
int type;
--
2.34.1.877.g7d5b0a3b8a6
next prev parent reply other threads:[~2021-11-30 21:38 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 21:38 [PATCH 00/12] reflog + gc: refactor, progress output, reftable-readyness Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 01/12] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 02/12] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 03/12] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 04/12] reflog expire: don't do negative comparison on enum values Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 05/12] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 06/12] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 07/12] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 08/12] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` Ævar Arnfjörð Bjarmason [this message]
2021-11-30 21:38 ` [PATCH 10/12] reflog expire: add progress output on --stale-fix Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 11/12] gc + reflog: emit progress output from "reflog expire --all" Ævar Arnfjörð Bjarmason
2021-11-30 21:38 ` [PATCH 12/12] gc + reflog: don't stall before initial "git gc" progress output Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 0/9] reftable prep: have builtin/reflog.c handle "--verbose" Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 1/9] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 2/9] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 3/9] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 4/9] reflog expire: don't do negative comparison on enum values Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 5/9] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 6/9] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 7/9] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 8/9] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-12-16 13:45 ` [PATCH v2 9/9] reflog + refs-backend: move "verbose" out of the backend Ævar Arnfjörð Bjarmason
2021-12-16 22:27 ` [PATCH v2 0/9] reftable prep: have builtin/reflog.c handle "--verbose" Junio C Hamano
2021-12-16 23:31 ` Ævar Arnfjörð Bjarmason
2021-12-21 14:24 ` Han-Wen Nienhuys
2021-12-21 15:21 ` Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 1/9] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 2/9] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 3/9] reflog: change one->many worktree->refnames to use a string_list Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 4/9] reflog expire: use "switch" over enum values Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 5/9] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 6/9] reflog expire: don't use lookup_commit_reference_gently() Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 7/9] reflog: reduce scope of "struct rev_info" Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 8/9] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Ævar Arnfjörð Bjarmason
2021-12-22 4:06 ` [PATCH v3 9/9] reflog + refs-backend: move "verbose" out of the backend Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-09.12-6a8f3915898-20211130T213319Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hanwen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).