Skip to content

Commit

Permalink
bundle-uri: parse bundle.heuristic=creationToken
Browse files Browse the repository at this point in the history
The bundle.heuristic value communicates that the bundle list is
organized to make use of the bundle.<id>.creationToken values that may
be provided in the bundle list. Those values will create a total order
on the bundles, allowing the Git client to download them in a specific
order and even remember previously-downloaded bundles by storing the
maximum creation token value.

Before implementing any logic that parses or uses the
bundle.<id>.creationToken values, teach Git to parse the
bundle.heuristic value from a bundle list. We can use 'test-tool
bundle-uri' to print the heuristic value and verify that the parsing
works correctly.

As an extra precaution, create the internal 'heuristics' array to be a
list of (enum, string) pairs so we can iterate through the array entries
carefully, regardless of the enum values.

Signed-off-by: Derrick Stolee <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
derrickstolee authored and gitster committed Jan 31, 2023
1 parent 7bc73e7 commit c93c3d2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Documentation/config/bundle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ bundle.mode::
complete understanding of the bundled information (`all`) or if any one
of the listed bundle URIs is sufficient (`any`).

bundle.heuristic::
If this string-valued key exists, then the bundle list is designed to
work well with incremental `git fetch` commands. The heuristic signals
that there are additional keys available for each bundle that help
determine which subset of bundles the client should download. The
only value currently understood is `creationToken`.

bundle.<id>.*::
The `bundle.<id>.*` keys are used to describe a single item in the
bundle list, grouped under `<id>` for identification purposes.
Expand Down
34 changes: 34 additions & 0 deletions bundle-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include "config.h"
#include "remote.h"

static struct {
enum bundle_list_heuristic heuristic;
const char *name;
} heuristics[BUNDLE_HEURISTIC__COUNT] = {
{ BUNDLE_HEURISTIC_NONE, ""},
{ BUNDLE_HEURISTIC_CREATIONTOKEN, "creationToken" },
};

static int compare_bundles(const void *hashmap_cmp_fn_data,
const struct hashmap_entry *he1,
const struct hashmap_entry *he2,
Expand Down Expand Up @@ -100,6 +108,17 @@ void print_bundle_list(FILE *fp, struct bundle_list *list)
fprintf(fp, "\tversion = %d\n", list->version);
fprintf(fp, "\tmode = %s\n", mode);

if (list->heuristic) {
int i;
for (i = 0; i < BUNDLE_HEURISTIC__COUNT; i++) {
if (heuristics[i].heuristic == list->heuristic) {
printf("\theuristic = %s\n",
heuristics[list->heuristic].name);
break;
}
}
}

for_all_bundles_in_list(list, summarize_bundle, fp);
}

Expand Down Expand Up @@ -142,6 +161,21 @@ static int bundle_list_update(const char *key, const char *value,
return 0;
}

if (!strcmp(subkey, "heuristic")) {
int i;
for (i = 0; i < BUNDLE_HEURISTIC__COUNT; i++) {
if (heuristics[i].heuristic &&
heuristics[i].name &&
!strcmp(value, heuristics[i].name)) {
list->heuristic = heuristics[i].heuristic;
return 0;
}
}

/* Ignore unknown heuristics. */
return 0;
}

/* Ignore other unknown global keys. */
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions bundle-uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ enum bundle_list_mode {
BUNDLE_MODE_ANY
};

enum bundle_list_heuristic {
BUNDLE_HEURISTIC_NONE = 0,
BUNDLE_HEURISTIC_CREATIONTOKEN,

/* Must be last. */
BUNDLE_HEURISTIC__COUNT
};

/**
* A bundle_list contains an unordered set of remote_bundle_info structs,
* as well as information about the bundle listing, such as version and
Expand All @@ -75,6 +83,12 @@ struct bundle_list {
* advertised by the bundle list at that location.
*/
char *baseURI;

/**
* A list can have a heuristic, which helps reduce the number of
* downloaded bundles.
*/
enum bundle_list_heuristic heuristic;
};

void init_bundle_list(struct bundle_list *list);
Expand Down
19 changes: 19 additions & 0 deletions t/t5750-bundle-uri-parse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,23 @@ test_expect_success 'parse config format edge cases: empty key or value' '
test_cmp_config_output expect actual
'

test_expect_success 'parse config format: creationToken heuristic' '
cat >expect <<-\EOF &&
[bundle]
version = 1
mode = all
heuristic = creationToken
[bundle "one"]
uri = http://example.com/bundle.bdl
[bundle "two"]
uri = https://example.com/bundle.bdl
[bundle "three"]
uri = file:///usr/share/git/bundle.bdl
EOF
test-tool bundle-uri parse-config expect >actual 2>err &&
test_must_be_empty err &&
test_cmp_config_output expect actual
'

test_done

0 comments on commit c93c3d2

Please sign in to comment.