Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Documentation/RelNotes/2.52.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ UI, Workflows & Features
* "git send-email" learned to drive "git imap-send" to store already
sent e-mails in an IMAP folder.

* The "promisor-remote" capability mechanism has been updated to
allow the "partialCloneFilter" settings and the "token" value to be
communicated from the server side.


Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
Expand Down Expand Up @@ -205,6 +209,14 @@ including security updates, are included in this release.
characters, which has been fixed.
(merge 8655908b9e jc/longer-disambiguation-fix later to maint).

* Some among "git add -p" and friends ignored color.diff and/or
color.ui configuration variables, which is an old regression, which
has been corrected.
(merge 1092cd6435 jk/add-i-color later to maint).

* "git subtree" (in contrib/) did not work correctly when splitting
squashed subtrees, which has been improved.

* Other code cleanup, docfix, build fix, etc.
(merge 823d537fa7 kh/doc-git-log-markup-fix later to maint).
(merge cf7efa4f33 rj/t6137-cygwin-fix later to maint).
Expand All @@ -229,3 +241,4 @@ including security updates, are included in this release.
(merge 31397bc4f7 kh/doc-fast-import-markup-fix later to maint).
(merge ac7096723b jc/doc-includeif-hasconfig-remote-url-fix later to maint).
(merge fafc9b08b8 ag/doc-sendmail-gmail-example-update later to maint).
(merge a66fc22bf9 rs/get-oid-with-flags-cleanup later to maint).
61 changes: 61 additions & 0 deletions Documentation/config/promisor.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ promisor.advertise::
"false", which means the "promisor-remote" capability is not
advertised.

promisor.sendFields::
A comma or space separated list of additional remote related
field names. A server sends these field names and the
associated field values from its configuration when
advertising its promisor remotes using the "promisor-remote"
capability, see linkgit:gitprotocol-v2[5]. Currently, only the
"partialCloneFilter" and "token" field names are supported.
+
`partialCloneFilter`:: contains the partial clone filter
used for the remote.
+
`token`:: contains an authentication token for the remote.
+
When a field name is part of this list and a corresponding
"remote.foo.<field-name>" config variable is set on the server to a
non-empty value, then the field name and value are sent when
advertising the promisor remote "foo".
+
This list has no effect unless the "promisor.advertise" config
variable is set to "true", and the "name" and "url" fields are always
advertised regardless of this setting.

promisor.acceptFromServer::
If set to "all", a client will accept all the promisor remotes
a server might advertise using the "promisor-remote"
Expand All @@ -28,3 +50,42 @@ promisor.acceptFromServer::
lazily fetchable from this promisor remote from its responses
to "fetch" and "clone" requests from the client. Name and URL
comparisons are case sensitive. See linkgit:gitprotocol-v2[5].

promisor.checkFields::
A comma or space separated list of additional remote related
field names. A client checks if the values of these fields
transmitted by a server correspond to the values of these
fields in its own configuration before accepting a promisor
remote. Currently, "partialCloneFilter" and "token" are the
only supported field names.
+
If one of these field names (e.g., "token") is being checked for an
advertised promisor remote (e.g., "foo"), three conditions must be met
for the check of this specific field to pass:
+
1. The corresponding local configuration (e.g., `remote.foo.token`)
must be set.
2. The server must advertise the "token" field for remote "foo".
3. The value of the locally configured `remote.foo.token` must exactly
match the value advertised by the server for the "token" field.
+
If any of these conditions is not met for any field name listed in
`promisor.checkFields`, the advertised remote "foo" is rejected.
+
For the "partialCloneFilter" field, this allows the client to ensure
that the server's filter matches what it expects locally, preventing
inconsistencies in filtering behavior. For the "token" field, this can
be used to verify that authentication credentials match expected
values.
+
Field values are compared case-sensitively.
+
The "name" and "url" fields are always checked according to the
`promisor.acceptFromServer` policy, independently of this setting.
+
The field names and values should be passed by the server through the
"promisor-remote" capability by using the `promisor.sendFields` config
variable. The fields are checked only if the
`promisor.acceptFromServer` config variable is not set to "None". If
set to "None", this config variable has no effect. See
linkgit:gitprotocol-v2[5].
64 changes: 48 additions & 16 deletions Documentation/gitprotocol-v2.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -785,33 +785,64 @@ retrieving the header from a bundle at the indicated URI, and thus
save themselves and the server(s) the request(s) needed to inspect the
headers of that bundle or bundles.

promisor-remote=<pr-infos>
~~~~~~~~~~~~~~~~~~~~~~~~~~
promisor-remote=<pr-info>
~~~~~~~~~~~~~~~~~~~~~~~~~

The server may advertise some promisor remotes it is using or knows
about to a client which may want to use them as its promisor remotes,
instead of this repository. In this case <pr-infos> should be of the
instead of this repository. In this case <pr-info> should be of the
form:

pr-infos = pr-info | pr-infos ";" pr-info
pr-info = pr-fields | pr-info ";" pr-fields

pr-info = "name=" pr-name | "name=" pr-name "," "url=" pr-url
pr-fields = pr-field | pr-fields "," pr-field

where `pr-name` is the urlencoded name of a promisor remote, and
`pr-url` the urlencoded URL of that promisor remote.
pr-field = field-name "=" field-value

In this case, if the client decides to use one or more promisor
remotes the server advertised, it can reply with
"promisor-remote=<pr-names>" where <pr-names> should be of the form:
where all the `field-name` and `field-value` in a given `pr-fields`
are field names and values related to a single promisor remote. A
given `field-name` MUST NOT appear more than once in given
`pr-fields`.

The server MUST advertise at least the "name" and "url" field names
along with the associated field values, which are the name of a valid
remote and its URL, in each `pr-fields`. The "name" and "url" fields
MUST appear first in each pr-fields, in that order.

After these mandatory fields, the server MAY advertise the following
optional fields in any order:

`partialCloneFilter`:: The filter specification used by the remote.
Clients can use this to determine if the remote's filtering strategy
is compatible with their needs (e.g., checking if both use "blob:none").
It corresponds to the "remote.<name>.partialCloneFilter" config setting.

`token`:: An authentication token that clients can use when
connecting to the remote. It corresponds to the "remote.<name>.token"
config setting.

No other fields are defined by the protocol at this time. Field names
are case-sensitive and MUST be transmitted exactly as specified
above. Clients MUST ignore fields they don't recognize to allow for
future protocol extensions.

For now, the client can only use information transmitted through these
fields to decide if it accepts the advertised promisor remote. In the
future that information might be used for other purposes though.

Field values MUST be urlencoded.

If the client decides to use one or more promisor remotes the server
advertised, it can reply with "promisor-remote=<pr-names>" where
<pr-names> should be of the form:

pr-names = pr-name | pr-names ";" pr-name

where `pr-name` is the urlencoded name of a promisor remote the server
advertised and the client accepts.

Note that, everywhere in this document, `pr-name` MUST be a valid
remote name, and the ';' and ',' characters MUST be encoded if they
appear in `pr-name` or `pr-url`.
Note that, everywhere in this document, the ';' and ',' characters
MUST be encoded if they appear in `pr-name` or `field-value`.

If the server doesn't know any promisor remote that could be good for
a client to use, or prefers a client not to use any promisor remote it
Expand All @@ -822,9 +853,10 @@ In this case, or if the client doesn't want to use any promisor remote
the server advertised, the client shouldn't advertise the
"promisor-remote" capability at all in its reply.

The "promisor.advertise" and "promisor.acceptFromServer" configuration
options can be used on the server and client side to control what they
advertise or accept respectively. See the documentation of these
On the server side, the "promisor.advertise" and "promisor.sendFields"
configuration options can be used to control what it advertises. On
the client side, the "promisor.acceptFromServer" configuration option
can be used to control what it accepts. See the documentation of these
configuration options for more information.

Note that in the future it would be nice if the "promisor-remote"
Expand Down
88 changes: 55 additions & 33 deletions add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#include "prompt.h"
#include "tree.h"

static void init_color(struct repository *r, struct add_i_state *s,
static void init_color(struct repository *r, int use_color,
const char *section_and_slot, char *dst,
const char *default_color)
{
char *key = xstrfmt("color.%s", section_and_slot);
const char *value;

if (!s->use_color)
if (!use_color)
dst[0] = '\0';
else if (repo_config_get_value(r, key, &value) ||
color_parse(value, dst))
Expand All @@ -36,42 +36,63 @@ static void init_color(struct repository *r, struct add_i_state *s,
free(key);
}

void init_add_i_state(struct add_i_state *s, struct repository *r,
struct add_p_opt *add_p_opt)
static int check_color_config(struct repository *r, const char *var)
{
const char *value;
int ret;

if (repo_config_get_value(r, var, &value))
ret = -1;
else
ret = git_config_colorbool(var, value);

/*
* Do not rely on want_color() to fall back to color.ui for us. It uses
* the value parsed by git_color_config(), which may not have been
* called by the main command.
*/
if (ret < 0 && !repo_config_get_value(r, "color.ui", &value))
ret = git_config_colorbool("color.ui", value);

return want_color(ret);
}

void init_add_i_state(struct add_i_state *s, struct repository *r,
struct add_p_opt *add_p_opt)
{
s->r = r;
s->context = -1;
s->interhunkcontext = -1;

if (repo_config_get_value(r, "color.interactive", &value))
s->use_color = -1;
else
s->use_color =
git_config_colorbool("color.interactive", value);
s->use_color = want_color(s->use_color);

init_color(r, s, "interactive.header", s->header_color, GIT_COLOR_BOLD);
init_color(r, s, "interactive.help", s->help_color, GIT_COLOR_BOLD_RED);
init_color(r, s, "interactive.prompt", s->prompt_color,
GIT_COLOR_BOLD_BLUE);
init_color(r, s, "interactive.error", s->error_color,
GIT_COLOR_BOLD_RED);

init_color(r, s, "diff.frag", s->fraginfo_color,
diff_get_color(s->use_color, DIFF_FRAGINFO));
init_color(r, s, "diff.context", s->context_color, "fall back");
s->use_color_interactive = check_color_config(r, "color.interactive");

init_color(r, s->use_color_interactive, "interactive.header",
s->header_color, GIT_COLOR_BOLD);
init_color(r, s->use_color_interactive, "interactive.help",
s->help_color, GIT_COLOR_BOLD_RED);
init_color(r, s->use_color_interactive, "interactive.prompt",
s->prompt_color, GIT_COLOR_BOLD_BLUE);
init_color(r, s->use_color_interactive, "interactive.error",
s->error_color, GIT_COLOR_BOLD_RED);
strlcpy(s->reset_color_interactive,
s->use_color_interactive ? GIT_COLOR_RESET : "", COLOR_MAXLEN);

s->use_color_diff = check_color_config(r, "color.diff");

init_color(r, s->use_color_diff, "diff.frag", s->fraginfo_color,
diff_get_color(s->use_color_diff, DIFF_FRAGINFO));
init_color(r, s->use_color_diff, "diff.context", s->context_color,
"fall back");
if (!strcmp(s->context_color, "fall back"))
init_color(r, s, "diff.plain", s->context_color,
diff_get_color(s->use_color, DIFF_CONTEXT));
init_color(r, s, "diff.old", s->file_old_color,
diff_get_color(s->use_color, DIFF_FILE_OLD));
init_color(r, s, "diff.new", s->file_new_color,
diff_get_color(s->use_color, DIFF_FILE_NEW));

strlcpy(s->reset_color,
s->use_color ? GIT_COLOR_RESET : "", COLOR_MAXLEN);
init_color(r, s->use_color_diff, "diff.plain",
s->context_color,
diff_get_color(s->use_color_diff, DIFF_CONTEXT));
init_color(r, s->use_color_diff, "diff.old", s->file_old_color,
diff_get_color(s->use_color_diff, DIFF_FILE_OLD));
init_color(r, s->use_color_diff, "diff.new", s->file_new_color,
diff_get_color(s->use_color_diff, DIFF_FILE_NEW));
strlcpy(s->reset_color_diff,
s->use_color_diff ? GIT_COLOR_RESET : "", COLOR_MAXLEN);

FREE_AND_NULL(s->interactive_diff_filter);
repo_config_get_string(r, "interactive.difffilter",
Expand Down Expand Up @@ -109,7 +130,8 @@ void clear_add_i_state(struct add_i_state *s)
FREE_AND_NULL(s->interactive_diff_filter);
FREE_AND_NULL(s->interactive_diff_algorithm);
memset(s, 0, sizeof(*s));
s->use_color = -1;
s->use_color_interactive = -1;
s->use_color_diff = -1;
}

/*
Expand Down Expand Up @@ -1188,9 +1210,9 @@ int run_add_i(struct repository *r, const struct pathspec *ps,
* When color was asked for, use the prompt color for
* highlighting, otherwise use square brackets.
*/
if (s.use_color) {
if (s.use_color_interactive) {
data.color = s.prompt_color;
data.reset = s.reset_color;
data.reset = s.reset_color_interactive;
}
print_file_item_data.color = data.color;
print_file_item_data.reset = data.reset;
Expand Down
7 changes: 5 additions & 2 deletions add-interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ struct add_p_opt {

struct add_i_state {
struct repository *r;
int use_color;
int use_color_interactive;
int use_color_diff;
char header_color[COLOR_MAXLEN];
char help_color[COLOR_MAXLEN];
char prompt_color[COLOR_MAXLEN];
char error_color[COLOR_MAXLEN];
char reset_color[COLOR_MAXLEN];
char reset_color_interactive[COLOR_MAXLEN];

char fraginfo_color[COLOR_MAXLEN];
char context_color[COLOR_MAXLEN];
char file_old_color[COLOR_MAXLEN];
char file_new_color[COLOR_MAXLEN];
char reset_color_diff[COLOR_MAXLEN];

int use_single_key;
char *interactive_diff_filter, *interactive_diff_algorithm;
Expand Down
12 changes: 6 additions & 6 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void err(struct add_p_state *s, const char *fmt, ...)
va_start(args, fmt);
fputs(s->s.error_color, stdout);
vprintf(fmt, args);
puts(s->s.reset_color);
puts(s->s.reset_color_interactive);
va_end(args);
}

Expand Down Expand Up @@ -457,7 +457,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
}
strbuf_complete_line(plain);

if (want_color_fd(1, -1)) {
if (want_color_fd(1, s->s.use_color_diff)) {
struct child_process colored_cp = CHILD_PROCESS_INIT;
const char *diff_filter = s->s.interactive_diff_filter;

Expand Down Expand Up @@ -714,7 +714,7 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
if (len)
strbuf_add(out, p, len);
else if (colored)
strbuf_addf(out, "%s\n", s->s.reset_color);
strbuf_addf(out, "%s\n", s->s.reset_color_diff);
else
strbuf_addch(out, '\n');
}
Expand Down Expand Up @@ -1107,7 +1107,7 @@ static void recolor_hunk(struct add_p_state *s, struct hunk *hunk)
s->s.file_new_color :
s->s.context_color);
strbuf_add(&s->colored, plain + current, eol - current);
strbuf_addstr(&s->colored, s->s.reset_color);
strbuf_addstr(&s->colored, s->s.reset_color_diff);
if (next > eol)
strbuf_add(&s->colored, plain + eol, next - eol);
current = next;
Expand Down Expand Up @@ -1528,8 +1528,8 @@ static int patch_update_file(struct add_p_state *s,
: 1));
printf(_(s->mode->prompt_mode[prompt_mode_type]),
s->buf.buf);
if (*s->s.reset_color)
fputs(s->s.reset_color, stdout);
if (*s->s.reset_color_interactive)
fputs(s->s.reset_color_interactive, stdout);
fflush(stdout);
if (read_single_character(s) == EOF)
break;
Expand Down
Loading