From: Derrick Stolee <derrickstolee@xxxxxxxxxx> If a bundle server is providing a table of contents with timestamps for the bundles, then we can store the most-recent timestamp and use that as a test if the bundle server has any new information. Teach 'git bundle fetch' to store the timestamp in the config file as 'fetch.bundleTimestamp' and compare the existing value to the most-recent timestamp in the bundle server's table of contents. If the new timestamp is at most the stored timestamp, then exit early (with success). If the new timestamp is greater than the stored timestamp, then continue with the normal fetch logic of downloading the most-recent bundle until all missing objects are satisfied. Store that new timestamp in the config for next time. RFC-TODO: Update documentation of 'git bundle fetch' to match his new behavior. RFC-TODO: Add 'fetch.bundleTimestamp' to Documentation/config/ RFC-TODO @ Ævar: I replaced the git_config_get_timestamp() with parse_expiry_date(), but as noted perhaps we want *nix epochs here only, in that case we could add an "isdigit" loop here. Signed-off-by: Derrick Stolee <derrickstolee@xxxxxxxxxx> --- builtin/bundle.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin/bundle.c b/builtin/bundle.c index c55d5215181..4c51b014f0b 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -413,6 +413,10 @@ static int cmd_bundle_fetch(int argc, const char **argv, const char *prefix) struct remote_bundle_info *stack = NULL; struct hashmap toc = { 0 }; const char *filter = NULL; + const char *timestamp_key = "fetch.bundletimestamp"; + timestamp_t stored_time = 0; + timestamp_t max_time = 0; + const char *value; struct option options[] = { OPT_BOOL(0, "progress", &progress, @@ -428,6 +432,17 @@ static int cmd_bundle_fetch(int argc, const char **argv, const char *prefix) if (!startup_info->have_repository) die(_("'fetch' requires a repository")); + /* + * TODO: Is it important re + * https://lore.kernel.org/git/220311.86pmmshahy.gmgdl@xxxxxxxxxxxxxxxxxxx/ + * that we don't accept "2.days.ago" etc., and only *nix + * epochs? + */ + if (!git_config_get_string_tmp(timestamp_key, &value) && + parse_expiry_date(value, &stored_time)) + return error(_("'%s' for '%s' is not a valid timestamp"), + value, timestamp_key); + /* * Step 1: determine protocol for uri, and download contents to * a temporary location. @@ -449,7 +464,6 @@ static int cmd_bundle_fetch(int argc, const char **argv, const char *prefix) } else { struct hashmap_iter iter; struct remote_bundle_info *info; - timestamp_t max_time = 0; /* populate a hashtable with all relevant bundles. */ used_hashmap = 1; @@ -480,6 +494,13 @@ static int cmd_bundle_fetch(int argc, const char **argv, const char *prefix) max_time = info->timestamp; } } + + trace2_data_intmax("bundle", the_repository, "max_time", max_time); + trace2_data_intmax("bundle", the_repository, "stored_time", stored_time); + + /* Skip fetching bundles if data isn't new enough. */ + if (max_time <= stored_time) + goto cleanup; } /* @@ -567,6 +588,14 @@ static int cmd_bundle_fetch(int argc, const char **argv, const char *prefix) stack = stack->stack_next; } + if (max_time) { + struct strbuf tstr = STRBUF_INIT; + strbuf_addf(&tstr, "%"PRIuMAX"", max_time); + git_config_set_gently(timestamp_key, tstr.buf); + strbuf_release(&tstr); + } + +cleanup: if (used_hashmap) { struct hashmap_iter iter; struct remote_bundle_info *info; -- 2.36.0.rc2.902.g60576bbc845