git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] credentials: make line reading Windows compatible

From
NGNikita Leonov via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 28, 2020, 11:40 UTC
Message-ID
<f69076036fe4dfe8b57fc1d4329c7be3f7346850.1601293224.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.710.v2.git.git.1601293224.gitgitgadget@gmail.com>
From: Nikita Leonov <nykyta.leonov@gmail.com>

This commit makes reading process regarding credentials compatible with 'CR/LF' line ending. It makes using git more convenient on systems like Windows.

Signed-off-by: Nikita Leonov <nykyta.leonov@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/credential-cache--daemon.c |  4 ++--
 builtin/credential-store.c         |  2 +-
 t/t0302-credential-store.sh        | 16 ++++++----------
 3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index c61f123a3b..17664bb0d5 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -99,12 +99,12 @@ static int read_request(FILE *fh, struct credential *c,
 	static struct strbuf item = STRBUF_INIT;
 	const char *p;
 
-	strbuf_getline_lf(&item, fh);
+	strbuf_getline(&item, fh);
 	if (!skip_prefix(item.buf, "action=", &p))
 		return error("client sent bogus action line: %s", item.buf);
 	strbuf_addstr(action, p);
 
-	strbuf_getline_lf(&item, fh);
+	strbuf_getline(&item, fh);
 	if (!skip_prefix(item.buf, "timeout=", &p))
 		return error("client sent bogus timeout line: %s", item.buf);
 	*timeout = atoi(p);
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index 5331ab151a..d4e90b68df 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -23,7 +23,7 @@ static int parse_credential_file(const char *fn,
 		return found_credential;
 	}
 
-	while (strbuf_getline_lf(&line, fh) != EOF) {
+	while (strbuf_getline(&line, fh) != EOF) {
 		if (!credential_from_url_gently(&entry, line.buf, 1) &&
 		    entry.username && entry.password &&
 		    credential_match(c, &entry)) {
diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index 716bf1af9f..f2c672e4b6 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -142,7 +142,7 @@ invalid_credential_test "scheme" ://user:pass@example.com
 invalid_credential_test "valid host/path" https://user:pass@
 invalid_credential_test "username/password" https://pass@example.com
 
-test_expect_success 'get: credentials with DOS line endings are invalid' '
+test_expect_success 'get: credentials with DOS line endings are valid' '
 	printf "https://user:pass@example.com\r\n" >"$HOME/.git-credentials" &&
 	check fill store <<-\EOF
 	protocol=https
@@ -150,11 +150,9 @@ test_expect_success 'get: credentials with DOS line endings are invalid' '
 	--
 	protocol=https
 	host=example.com
-	username=askpass-username
-	password=askpass-password
+	username=user
+	password=pass
 	--
-	askpass: Username for '\''https://example.com'\'':
-	askpass: Password for '\''https://askpass-username@example.com'\'':
 	--
 	EOF
 '
@@ -172,7 +170,7 @@ test_expect_success 'get: credentials with path and DOS line endings are valid'
 	EOF
 '
 
-test_expect_success 'get: credentials with DOS line endings are invalid if path is relevant' '
+test_expect_success 'get: credentials with DOS line endings are valid if path is relevant' '
 	printf "https://user:pass@example.com/repo.git\r\n" >"$HOME/.git-credentials" &&
 	test_config credential.useHttpPath true &&
 	check fill store <<-\EOF
@@ -181,11 +179,9 @@ test_expect_success 'get: credentials with DOS line endings are invalid if path
 	protocol=https
 	host=example.com
 	path=repo.git
-	username=askpass-username
-	password=askpass-password
+	username=user
+	password=pass
 	--
-	askpass: Username for '\''https://example.com/repo.git'\'':
-	askpass: Password for '\''https://askpass-username@example.com/repo.git'\'':
 	--
 	EOF
 '
-- 
gitgitgadget
Previous: Nikita Leonov via GitGitGadgetNext: Junio C Hamano
Message 13 of 32 in “credential.c: fix credential reading with regards to CR/LF”
  1. credential.c: fix credential reading with regards to CR/LFJohannes Schindelin via GitGitGadget, Feb 14, 2020
  2. Junio C HamanoFeb 14, 2020
  3. Jeff KingFeb 14, 2020
  4. 0/3 Prepare git credential to read input with DOS line endingsJohannes Schindelin via GitGitGadget, Sep 28, 2020
  5. 1/3 credential.c: fix credential reading with regards to CR/LFNikita Leonov via GitGitGadget, Sep 28, 2020
  6. Jeff KingSep 29, 2020
  7. Johannes SchindelinOct 2, 2020
  8. Jeff KingOct 2, 2020
  9. Johannes SchindelinOct 2, 2020
  10. Junio C HamanoOct 2, 2020
  11. Johannes SchindelinOct 3, 2020
  12. 3/3 docs: make notes regarding credential line readingNikita Leonov via GitGitGadget, Sep 28, 2020
  13. 2/3 credentials: make line reading Windows compatibleNikita Leonov via GitGitGadget, Sep 28, 2020
  14. Junio C HamanoSep 28, 2020
  15. Jeff KingSep 29, 2020
  16. Junio C HamanoSep 30, 2020
  17. Johannes SchindelinOct 2, 2020
  18. Carlo ArenasSep 28, 2020
  19. Junio C HamanoSep 28, 2020
  20. Jeff KingSep 29, 2020
  21. Junio C HamanoSep 29, 2020
  22. Jeff KingSep 29, 2020
  23. Junio C HamanoSep 29, 2020
  24. Jeff KingSep 29, 2020
  25. Junio C HamanoSep 30, 2020
  26. Jeff KingSep 30, 2020
  27. Junio C HamanoSep 30, 2020
  28. Jeff KingOct 1, 2020
  29. Junio C HamanoOct 1, 2020
  30. Johannes SchindelinOct 2, 2020
  31. Junio C HamanoSep 28, 2020
  32. credential: treat CR/LF as line endings in the credential protocolJohannes Schindelin via GitGitGadget, Oct 3, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.