Skip to content

Commit 6c27d22

Browse files
pks-tgitster
authored andcommitted
credential: stop using the_repository
Stop using `the_repository` in the "credential" subsystem by passing in a repository when filling, approving or rejecting credentials. Adjust callers accordingly by using `the_repository`. While there may be some callers that have a repository available in their context, this trivial conversion allows for easier verification and bubbles up the use of `the_repository` by one level. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71e5afe commit 6c27d22

File tree

6 files changed

+46
-43
lines changed

6 files changed

+46
-43
lines changed

builtin/credential.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ int cmd_credential(int argc,
3232
die("unable to read credential from stdin");
3333

3434
if (!strcmp(op, "fill")) {
35-
credential_fill(&c, 0);
35+
credential_fill(the_repository, &c, 0);
3636
credential_next_state(&c);
3737
credential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);
3838
} else if (!strcmp(op, "approve")) {
3939
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
40-
credential_approve(&c);
40+
credential_approve(the_repository, &c);
4141
} else if (!strcmp(op, "reject")) {
4242
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
43-
credential_reject(&c);
43+
credential_reject(the_repository, &c);
4444
} else {
4545
usage(usage_msg);
4646
}

credential.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -166,7 +165,7 @@ static int match_partial_url(const char *url, void *cb)
166165
return matches;
167166
}
168167

169-
static void credential_apply_config(struct credential *c)
168+
static void credential_apply_config(struct repository *r, struct credential *c)
170169
{
171170
char *normalized_url;
172171
struct urlmatch_config config = URLMATCH_CONFIG_INIT;
@@ -191,7 +190,7 @@ static void credential_apply_config(struct credential *c)
191190
credential_format(c, &url);
192191
normalized_url = url_normalize(url.buf, &config.url);
193192

194-
git_config(urlmatch_config_entry, &config);
193+
repo_config(r, urlmatch_config_entry, &config);
195194
string_list_clear(&config.vars, 1);
196195
free(normalized_url);
197196
urlmatch_config_release(&config);
@@ -254,34 +253,34 @@ static char *credential_ask_one(const char *what, struct credential *c,
254253
return xstrdup(r);
255254
}
256255

257-
static int credential_getpass(struct credential *c)
256+
static int credential_getpass(struct repository *r, struct credential *c)
258257
{
259258
int interactive;
260259
char *value;
261-
if (!git_config_get_maybe_bool("credential.interactive", &interactive) &&
260+
if (!repo_config_get_maybe_bool(r, "credential.interactive", &interactive) &&
262261
!interactive) {
263-
trace2_data_intmax("credential", the_repository,
262+
trace2_data_intmax("credential", r,
264263
"interactive/skipped", 1);
265264
return -1;
266265
}
267-
if (!git_config_get_string("credential.interactive", &value)) {
266+
if (!repo_config_get_string(r, "credential.interactive", &value)) {
268267
int same = !strcmp(value, "never");
269268
free(value);
270269
if (same) {
271-
trace2_data_intmax("credential", the_repository,
270+
trace2_data_intmax("credential", r,
272271
"interactive/skipped", 1);
273272
return -1;
274273
}
275274
}
276275

277-
trace2_region_enter("credential", "interactive", the_repository);
276+
trace2_region_enter("credential", "interactive", r);
278277
if (!c->username)
279278
c->username = credential_ask_one("Username", c,
280279
PROMPT_ASKPASS|PROMPT_ECHO);
281280
if (!c->password)
282281
c->password = credential_ask_one("Password", c,
283282
PROMPT_ASKPASS);
284-
trace2_region_leave("credential", "interactive", the_repository);
283+
trace2_region_leave("credential", "interactive", r);
285284

286285
return 0;
287286
}
@@ -489,7 +488,8 @@ static int credential_do(struct credential *c, const char *helper,
489488
return r;
490489
}
491490

492-
void credential_fill(struct credential *c, int all_capabilities)
491+
void credential_fill(struct repository *r,
492+
struct credential *c, int all_capabilities)
493493
{
494494
int i;
495495

@@ -499,7 +499,7 @@ void credential_fill(struct credential *c, int all_capabilities)
499499
credential_next_state(c);
500500
c->multistage = 0;
501501

502-
credential_apply_config(c);
502+
credential_apply_config(r, c);
503503
if (all_capabilities)
504504
credential_set_all_capabilities(c, CREDENTIAL_OP_INITIAL);
505505

@@ -526,12 +526,12 @@ void credential_fill(struct credential *c, int all_capabilities)
526526
c->helpers.items[i].string);
527527
}
528528

529-
if (credential_getpass(c) ||
529+
if (credential_getpass(r, c) ||
530530
(!c->username && !c->password && !c->credential))
531531
die("unable to get password from user");
532532
}
533533

534-
void credential_approve(struct credential *c)
534+
void credential_approve(struct repository *r, struct credential *c)
535535
{
536536
int i;
537537

@@ -542,20 +542,20 @@ void credential_approve(struct credential *c)
542542

543543
credential_next_state(c);
544544

545-
credential_apply_config(c);
545+
credential_apply_config(r, c);
546546

547547
for (i = 0; i < c->helpers.nr; i++)
548548
credential_do(c, c->helpers.items[i].string, "store");
549549
c->approved = 1;
550550
}
551551

552-
void credential_reject(struct credential *c)
552+
void credential_reject(struct repository *r, struct credential *c)
553553
{
554554
int i;
555555

556556
credential_next_state(c);
557557

558-
credential_apply_config(c);
558+
credential_apply_config(r, c);
559559

560560
for (i = 0; i < c->helpers.nr; i++)
561561
credential_do(c, c->helpers.items[i].string, "erase");

credential.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "string-list.h"
55
#include "strvec.h"
66

7+
struct repository;
8+
79
/**
810
* The credentials API provides an abstracted way of gathering
911
* authentication credentials from the user.
@@ -65,7 +67,7 @@
6567
* // Fill in the username and password fields by contacting
6668
* // helpers and/or asking the user. The function will die if it
6769
* // fails.
68-
* credential_fill(&c);
70+
* credential_fill(repo, &c);
6971
*
7072
* // Otherwise, we have a username and password. Try to use it.
7173
*
@@ -218,7 +220,8 @@ void credential_clear(struct credential *);
218220
* If all_capabilities is set, this is an internal user that is prepared
219221
* to deal with all known capabilities, and we should advertise that fact.
220222
*/
221-
void credential_fill(struct credential *, int all_capabilities);
223+
void credential_fill(struct repository *, struct credential *,
224+
int all_capabilities);
222225

223226
/**
224227
* Inform the credential subsystem that the provided credentials
@@ -227,7 +230,7 @@ void credential_fill(struct credential *, int all_capabilities);
227230
* that they may store the result to be used again. Any errors
228231
* from helpers are ignored.
229232
*/
230-
void credential_approve(struct credential *);
233+
void credential_approve(struct repository *, struct credential *);
231234

232235
/**
233236
* Inform the credential subsystem that the provided credentials
@@ -239,7 +242,7 @@ void credential_approve(struct credential *);
239242
* for another call to `credential_fill`). Any errors from helpers
240243
* are ignored.
241244
*/
242-
void credential_reject(struct credential *);
245+
void credential_reject(struct repository *, struct credential *);
243246

244247
/**
245248
* Enable all of the supported credential flags in this credential.

http.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static void init_curl_http_auth(CURL *result)
609609
}
610610
}
611611

612-
credential_fill(&http_auth, 1);
612+
credential_fill(the_repository, &http_auth, 1);
613613

614614
if (http_auth.password) {
615615
if (always_auth_proactively()) {
@@ -652,7 +652,7 @@ static void init_curl_proxy_auth(CURL *result)
652652
{
653653
if (proxy_auth.username) {
654654
if (!proxy_auth.password && !proxy_auth.credential)
655-
credential_fill(&proxy_auth, 1);
655+
credential_fill(the_repository, &proxy_auth, 1);
656656
set_proxyauth_name_password(result);
657657
}
658658

@@ -686,7 +686,7 @@ static int has_cert_password(void)
686686
cert_auth.host = xstrdup("");
687687
cert_auth.username = xstrdup("");
688688
cert_auth.path = xstrdup(ssl_cert);
689-
credential_fill(&cert_auth, 0);
689+
credential_fill(the_repository, &cert_auth, 0);
690690
}
691691
return 1;
692692
}
@@ -700,7 +700,7 @@ static int has_proxy_cert_password(void)
700700
proxy_cert_auth.host = xstrdup("");
701701
proxy_cert_auth.username = xstrdup("");
702702
proxy_cert_auth.path = xstrdup(http_proxy_ssl_cert);
703-
credential_fill(&proxy_cert_auth, 0);
703+
credential_fill(the_repository, &proxy_cert_auth, 0);
704704
}
705705
return 1;
706706
}
@@ -1784,9 +1784,9 @@ static int handle_curl_result(struct slot_results *results)
17841784
curl_errorstr, sizeof(curl_errorstr));
17851785

17861786
if (results->curl_result == CURLE_OK) {
1787-
credential_approve(&http_auth);
1788-
credential_approve(&proxy_auth);
1789-
credential_approve(&cert_auth);
1787+
credential_approve(the_repository, &http_auth);
1788+
credential_approve(the_repository, &proxy_auth);
1789+
credential_approve(the_repository, &cert_auth);
17901790
return HTTP_OK;
17911791
} else if (results->curl_result == CURLE_SSL_CERTPROBLEM) {
17921792
/*
@@ -1795,7 +1795,7 @@ static int handle_curl_result(struct slot_results *results)
17951795
* with the certificate. So we reject the credential to
17961796
* avoid caching or saving a bad password.
17971797
*/
1798-
credential_reject(&cert_auth);
1798+
credential_reject(the_repository, &cert_auth);
17991799
return HTTP_NOAUTH;
18001800
} else if (results->curl_result == CURLE_SSL_PINNEDPUBKEYNOTMATCH) {
18011801
return HTTP_NOMATCHPUBLICKEY;
@@ -1808,7 +1808,7 @@ static int handle_curl_result(struct slot_results *results)
18081808
credential_clear_secrets(&http_auth);
18091809
return HTTP_REAUTH;
18101810
}
1811-
credential_reject(&http_auth);
1811+
credential_reject(the_repository, &http_auth);
18121812
if (always_auth_proactively())
18131813
http_proactive_auth = PROACTIVE_AUTH_NONE;
18141814
return HTTP_NOAUTH;
@@ -1822,7 +1822,7 @@ static int handle_curl_result(struct slot_results *results)
18221822
}
18231823
} else {
18241824
if (results->http_connectcode == 407)
1825-
credential_reject(&proxy_auth);
1825+
credential_reject(the_repository, &proxy_auth);
18261826
if (!curl_errorstr[0])
18271827
strlcpy(curl_errorstr,
18281828
curl_easy_strerror(results->curl_result),
@@ -2210,7 +2210,7 @@ static int http_request_reauth(const char *url,
22102210
int ret;
22112211

22122212
if (always_auth_proactively())
2213-
credential_fill(&http_auth, 1);
2213+
credential_fill(the_repository, &http_auth, 1);
22142214

22152215
ret = http_request(url, result, target, options);
22162216

@@ -2251,7 +2251,7 @@ static int http_request_reauth(const char *url,
22512251
BUG("Unknown http_request target");
22522252
}
22532253

2254-
credential_fill(&http_auth, 1);
2254+
credential_fill(the_repository, &http_auth, 1);
22552255

22562256
ret = http_request(url, result, target, options);
22572257
}

imap-send.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static void server_fill_credential(struct imap_server_conf *srvc, struct credent
922922
cred->username = xstrdup_or_null(srvc->user);
923923
cred->password = xstrdup_or_null(srvc->pass);
924924

925-
credential_fill(cred, 1);
925+
credential_fill(the_repository, cred, 1);
926926

927927
if (!srvc->user)
928928
srvc->user = xstrdup(cred->username);
@@ -1123,7 +1123,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
11231123
} /* !preauth */
11241124

11251125
if (cred.username)
1126-
credential_approve(&cred);
1126+
credential_approve(the_repository, &cred);
11271127
credential_clear(&cred);
11281128

11291129
/* check the target mailbox exists */
@@ -1150,7 +1150,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
11501150

11511151
bail:
11521152
if (cred.username)
1153-
credential_reject(&cred);
1153+
credential_reject(the_repository, &cred);
11541154
credential_clear(&cred);
11551155

11561156
out:
@@ -1492,9 +1492,9 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
14921492

14931493
if (cred.username) {
14941494
if (res == CURLE_OK)
1495-
credential_approve(&cred);
1495+
credential_approve(the_repository, &cred);
14961496
else if (res == CURLE_LOGIN_DENIED)
1497-
credential_reject(&cred);
1497+
credential_reject(the_repository, &cred);
14981498
}
14991499

15001500
credential_clear(&cred);

remote-curl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
942942
do {
943943
err = probe_rpc(rpc, &results);
944944
if (err == HTTP_REAUTH)
945-
credential_fill(&http_auth, 0);
945+
credential_fill(the_repository, &http_auth, 0);
946946
} while (err == HTTP_REAUTH);
947947
if (err != HTTP_OK)
948948
return -1;
@@ -1064,7 +1064,7 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
10641064
rpc->any_written = 0;
10651065
err = run_slot(slot, NULL);
10661066
if (err == HTTP_REAUTH && !large_request) {
1067-
credential_fill(&http_auth, 0);
1067+
credential_fill(the_repository, &http_auth, 0);
10681068
curl_slist_free_all(headers);
10691069
goto retry;
10701070
}

0 commit comments

Comments
 (0)