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

[PATCH 1/4] Add --cacheinfo option to update-cache

From
Junio C Hamano <junkio@cox.net>
Date
Apr 15, 2005, 06:03 UTC
Message-ID
<7vmzs0o9uf.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vr7hco9z7.fsf@assigned-by-dhcp.cox.net>

This adds "--cacheinfo" option to update-cache. It is needed to manipulate dircache without actually having such a blob in the working directory. To pretend you have a file with mode-sha1 at path, say:

 $ update-cache --cacheinfo mode sha1 path
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 update-cache.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletion(-)
Index: update-cache.c
===================================================================
--- 6767883b330882bc0e9a7c1e4fd999c0ee97ba3a/update-cache.c  (mode:100644 sha1:6c1d608cff03d2126191c0891cf1d262d6ae7823)
+++ 21e5e9f7d7dfa81c6519f0204d5a467236c7fdd5/update-cache.c  (mode:100644 sha1:8e82862ee66dc339967de558e7a5a9c52ba37259)
@@ -250,6 +250,8 @@
 {
 	int i, newfd, entries;
 	int allow_options = 1;
+	const char *sha1_force = NULL;
+	const char *mode_force = NULL;
 
 	newfd = open(".git/index.lock", O_RDWR | O_CREAT | O_EXCL, 0600);
 	if (newfd < 0)
@@ -282,14 +284,35 @@
 				refresh_cache();
 				continue;
 			}
+			if (!strcmp(path, "--cacheinfo")) {
+				mode_force = argv[++i];
+				sha1_force = argv[++i];
+				continue;
+			}
 			die("unknown option %s", path);
 		}
 		if (!verify_path(path)) {
 			fprintf(stderr, "Ignoring path %s\n", argv[i]);
 			continue;
 		}
-		if (add_file_to_cache(path))
+		if (sha1_force && mode_force) {
+			struct cache_entry *ce;
+			int namelen = strlen(path);
+			int mode;
+			int size = cache_entry_size(namelen);
+			sscanf(mode_force, "%o", &mode);
+			ce = malloc(size);
+			memset(ce, 0, size);
+			memcpy(ce->name, path, namelen);
+			ce->namelen = namelen;
+			ce->st_mode = mode;
+			get_sha1_hex(sha1_force, ce->sha1);
+
+			add_cache_entry(ce, 1);
+		}
+		else if (add_file_to_cache(path))
 			die("Unable to add %s to database", path);
+		mode_force = sha1_force = NULL;
 	}
 	if (write_cache(newfd, active_cache, active_nr) ||
 	    rename(".git/index.lock", ".git/index"))
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 5 in “Merging merge-trees changes to pasky-0.4”
  1. 0/4 Merging merge-trees changes to pasky-0.4Junio C Hamano, Apr 15, 2005
  2. 1/4 Add --cacheinfo option to update-cacheJunio C Hamano, Apr 15, 2005
  3. 2/4 Add -z option to show-filesJunio C Hamano, Apr 15, 2005
  4. 3/4 Add -r and -z options to ls-treeJunio C Hamano, Apr 15, 2005
  5. 4/4 Makefile change and merge-trees script itself.Junio C Hamano, Apr 15, 2005

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.