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

[PATCH v5 1/2] read-cache: factor out get_sha1_from_index() helper

From
tboegi@web.de <tboegi@web.de>
Date
May 19, 2016, 14:21 UTC
Message-ID
<1463667678-25969-1-git-send-email-tboegi@web.de>
In-Reply-To
<573A993F.8020205@web.de>
From: Torsten Bögershausen <tboegi@web.de>

Factor out the retrieval of the sha1 for a given path in read_blob_data_from_index() into the function get_sha1_from_index().

This will be used in the next commit, when convert.c can do the analyze for "text=auto" without slurping the whole blob into memory at once.

Add a wrapper definition get_sha1_from_cache().
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 cache.h      |  3 +++
 read-cache.c | 29 ++++++++++++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/cache.h b/cache.h
index 160f8e3..15a2a10 100644
--- a/cache.h
+++ b/cache.h
@@ -379,6 +379,7 @@ extern void free_name_hash(struct index_state *istate);
 #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
 #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
 #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
+#define get_sha1_from_cache(path)  get_sha1_from_index (&the_index, (path))
 #endif
 
 enum object_type {
@@ -1038,6 +1039,8 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
 	return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
 }
 
+const unsigned char *get_sha1_from_index(struct index_state *istate, const char *path);
+
 /*
  * This internal function is only declared here for the benefit of
  * lookup_replace_object().  Please do not call it directly.
diff --git a/read-cache.c b/read-cache.c
index d9fb78b..a3ef967 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2263,13 +2263,27 @@ int index_name_is_other(const struct index_state *istate, const char *name,
 
 void *read_blob_data_from_index(struct index_state *istate, const char *path, unsigned long *size)
 {
-	int pos, len;
+	const unsigned char *sha1;
 	unsigned long sz;
 	enum object_type type;
 	void *data;
 
-	len = strlen(path);
-	pos = index_name_pos(istate, path, len);
+	sha1 = get_sha1_from_index(istate, path);
+	if (!sha1)
+		return NULL;
+	data = read_sha1_file(sha1, &type, &sz);
+	if (!data || type != OBJ_BLOB) {
+		free(data);
+		return NULL;
+	}
+	if (size)
+		*size = sz;
+	return data;
+}
+
+const unsigned char *get_sha1_from_index(struct index_state *istate, const char *path)
+{
+	int pos = index_name_pos(istate, path, strlen(path));
 	if (pos < 0) {
 		/*
 		 * We might be in the middle of a merge, in which
@@ -2285,14 +2299,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path, un
 	}
 	if (pos < 0)
 		return NULL;
-	data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);
-	if (!data || type != OBJ_BLOB) {
-		free(data);
-		return NULL;
-	}
-	if (size)
-		*size = sz;
-	return data;
+	return (istate->cache[pos]->sha1);
 }
 
 void stat_validity_clear(struct stat_validity *sv)
-- 
2.0.0.rc1.6318.g0c2c796
Previous: Junio C HamanoNext: tboegi@web.de
Message 32 of 53 in “Bug report: Duplicate CRLF rewrite warnings on commit”
  1. Adam DinwoodieMay 13, 2016
  2. Junio C HamanoMay 13, 2016
  3. Torsten BögershausenMay 14, 2016
  4. Adam DinwoodieMay 14, 2016
  5. Jeff KingMay 13, 2016
  6. Junio C HamanoMay 13, 2016
  7. Jeff KingMay 13, 2016
  8. 0/1 Quickfix ?No duplicate CRLF rewrite warnings on committboegi@web.de, May 15, 2016
  9. 1/1 No duplicate CRLF rewrite warnings on committboegi@web.de, May 15, 2016
  10. Eric SunshineMay 15, 2016
  11. 0/3 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 15, 2016
  12. 1/3 t6038; use crlf on all platformstboegi@web.de, May 15, 2016
  13. Eric SunshineMay 15, 2016
  14. 2/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 15, 2016
  15. Eric SunshineMay 15, 2016
  16. 3/3 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 15, 2016
  17. Eric SunshineMay 15, 2016
  18. Junio C HamanoMay 15, 2016
  19. 0/1 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 16, 2016
  20. Junio C HamanoMay 16, 2016
  21. Torsten BögershausenMay 17, 2016
  22. 1/1 t6038; use crlf on all platformstboegi@web.de, May 17, 2016
  23. Junio C HamanoMay 17, 2016
  24. 0/2 CRLF: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 17, 2016
  25. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 17, 2016
  26. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 17, 2016
  27. Junio C HamanoMay 17, 2016
  28. Torsten BögershausenMay 18, 2016
  29. Torsten BögershausenMay 18, 2016
  30. 0/2 CRLF: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 19, 2016
  31. Junio C HamanoMay 19, 2016
  32. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 19, 2016
  33. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 19, 2016
  34. Junio C HamanoMay 19, 2016
  35. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 20, 2016
  36. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 20, 2016
  37. Junio C HamanoMay 20, 2016
  38. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 21, 2016
  39. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 21, 2016
  40. Junio C HamanoMay 24, 2016
  41. 1/1 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 16, 2016
  42. 0/1 t6038-merge-text-auto.shtboegi@web.de, May 30, 2016
  43. Junio C HamanoMay 30, 2016
  44. Junio C HamanoMay 30, 2016
  45. 1/1 t6038: different eol for "Merge addition of text=auto"tboegi@web.de, May 30, 2016
  46. 0/3 unified auto CRLF handling, V2tboegi@web.de, Jun 7, 2016
  47. 1/3 convert: unify the "auto" handling of CRLFtboegi@web.de, Jun 7, 2016
  48. 2/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, Jun 7, 2016
  49. 3/3 Correct ce_compare_data() in a middle of a mergetboegi@web.de, Jun 7, 2016
  50. 0/3 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 15, 2016
  51. 1/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 15, 2016
  52. 2/3 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 15, 2016
  53. 3/3 t6038; use crlf on all platformstboegi@web.de, May 15, 2016

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.