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

[PATCH v2 2/2] osxkeychain: state[] seen=1 to skip unnecessary store operations

From
Koji Nakamaru via GitGitGadget <gitgitgadget@gmail.com>
Date
May 11, 2024, 11:55 UTC
Message-ID
<1f57718abff1d0e234c4145e833424da7be79311.1715428542.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1729.v2.git.1715428542.gitgitgadget@gmail.com>
From: Koji Nakamaru <koji.nakamaru@gree.net>

Records whether credentials come from get operations and skips unnecessary store operations by utilizing the state[] feature, as suggested by brian m. carlson.

Signed-off-by: Koji Nakamaru <koji.nakamaru@gree.net>
---
 .../osxkeychain/git-credential-osxkeychain.c          | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/contrib/credential/osxkeychain/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
index 0884db48d0a..6ce22a28ed7 100644
--- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c
+++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
@@ -12,6 +12,7 @@ static CFStringRef username;
 static CFDataRef password;
 static CFDataRef password_expiry_utc;
 static CFDataRef oauth_refresh_token;
+static int state_seen;
 
 static void clear_credential(void)
 {
@@ -171,6 +172,9 @@ static OSStatus find_internet_password(void)
 
 	CFRelease(item);
 
+	write_item("capability[]", "state", strlen("state"));
+	write_item("state[]", "osxkeychain:seen=1", strlen("osxkeychain:seen=1"));
+
 out:
 	CFRelease(attrs);
 
@@ -284,6 +288,9 @@ static OSStatus add_internet_password(void)
 	CFDictionaryRef attrs;
 	OSStatus result;
 
+	if (state_seen)
+		return errSecSuccess;
+
 	/* Only store complete credentials */
 	if (!protocol || !host || !username || !password)
 		return -1;
@@ -395,6 +402,10 @@ static void read_credential(void)
 			oauth_refresh_token = CFDataCreate(kCFAllocatorDefault,
 							   (UInt8 *)v,
 							   strlen(v));
+		else if (!strcmp(buf, "state[]")) {
+			if (!strcmp(v, "osxkeychain:seen=1"))
+				state_seen = 1;
+		}
 		/*
 		 * Ignore other lines; we don't know what they mean, but
 		 * this future-proofs us when later versions of git do
-- 
gitgitgadget
Previous: Koji NakamaruNext: Junio C Hamano
Message 14 of 21 in “osxkeychain: lock for exclusive execution”
  1. osxkeychain: lock for exclusive executionKoji Nakamaru via GitGitGadget, May 10, 2024
  2. Bo AndersonMay 10, 2024
  3. Jeff KingMay 10, 2024
  4. brian m. carlsonMay 10, 2024
  5. Jeff KingMay 10, 2024
  6. brian m. carlsonMay 10, 2024
  7. Junio C HamanoMay 10, 2024
  8. Jeff KingMay 10, 2024
  9. Junio C HamanoMay 10, 2024
  10. 0/2 osxkeychain: lock for exclusive executionKoji Nakamaru via GitGitGadget, May 11, 2024
  11. 1/2 osxkeychain: lock for exclusive executionKoji Nakamaru via GitGitGadget, May 11, 2024
  12. Junio C HamanoMay 12, 2024
  13. Koji NakamaruMay 12, 2024
  14. 2/2 osxkeychain: state[] seen=1 to skip unnecessary store operationsKoji Nakamaru via GitGitGadget, May 11, 2024
  15. Junio C HamanoMay 12, 2024
  16. Koji NakamaruMay 12, 2024
  17. 0/2 osxkeychain: lock for exclusive executionKoji Nakamaru via GitGitGadget, May 15, 2024
  18. 1/2 osxkeychain: exclusive lock to serialize execution of operationsKoji Nakamaru via GitGitGadget, May 15, 2024
  19. 2/2 osxkeychain: state to skip unnecessary store operationsKoji Nakamaru via GitGitGadget, May 15, 2024
  20. Koji NakamaruMay 15, 2024
  21. Koji NakamaruMay 10, 2024

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.