{"thread":{"id":"33492","subject":"[PATCH 1/3] Make read_index_data() public","startedAt":"2013-04-12T17:26:10Z","lastAt":"2013-04-14T20:14:15Z","messageCount":12,"participants":["Lukas Fleischer","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"214079","messageId":"1365787573-597-1-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":null,"subject":"[PATCH 0/3] Remove ~25 lines of duplicate code","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-12T17:26:10Z","receivedAt":"2013-04-12T17:26:10Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"Merge read_index_data() and has_cr_in_index() which are almost 1:1\ncopies of each other.\n\nLukas Fleischer (3):\n  Make read_index_data() public\n  Add size parameter to read_index_data()\n  convert.c: Remove duplicate code\n\n attr.c       | 35 +----------------------------------\n cache.h      |  1 +\n convert.c    | 27 ++-------------------------\n read-cache.c | 36 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 40 insertions(+), 59 deletions(-)\n\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214078","messageId":"1365787573-597-2-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365787573-597-1-git-send-email-git@cryptocrack.de","subject":"[PATCH 1/3] Make read_index_data() public","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-12T17:26:11Z","receivedAt":"2013-04-12T17:26:11Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"This allows for reusing the function in convert.c later.\n\nAlso, move it from attr.c to read-cache.c and add a use_index parameter\nto specify a custom index_state since we are no longer enable to access\nthe static use_index variable from attr.c.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\nI am not totally sure whether read-cache.c is the best place for this...\n\n attr.c       | 35 +----------------------------------\n cache.h      |  1 +\n read-cache.c | 33 +++++++++++++++++++++++++++++++++\n 3 files changed, 35 insertions(+), 34 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 689bc2a..2e1ce7b 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -381,46 +381,13 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)\n \treturn res;\n }\n \n-static void *read_index_data(const char *path)\n-{\n-\tint pos, len;\n-\tunsigned long sz;\n-\tenum object_type type;\n-\tvoid *data;\n-\tstruct index_state *istate = use_index ? use_index : &the_index;\n-\n-\tlen = strlen(path);\n-\tpos = index_name_pos(istate, path, len);\n-\tif (pos < 0) {\n-\t\t/*\n-\t\t * We might be in the middle of a merge, in which\n-\t\t * case we would read stage #2 (ours).\n-\t\t */\n-\t\tint i;\n-\t\tfor (i = -pos - 1;\n-\t\t     (pos < 0 && i < istate->cache_nr &&\n-\t\t      !strcmp(istate->cache[i]->name, path));\n-\t\t     i++)\n-\t\t\tif (ce_stage(istate->cache[i]) == 2)\n-\t\t\t\tpos = i;\n-\t}\n-\tif (pos < 0)\n-\t\treturn NULL;\n-\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n-\tif (!data || type != OBJ_BLOB) {\n-\t\tfree(data);\n-\t\treturn NULL;\n-\t}\n-\treturn data;\n-}\n-\n static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n {\n \tstruct attr_stack *res;\n \tchar *buf, *sp;\n \tint lineno = 0;\n \n-\tbuf = read_index_data(path);\n+\tbuf = read_index_data(path, use_index);\n \tif (!buf)\n \t\treturn NULL;\n \ndiff --git a/cache.h b/cache.h\nindex ba5a47c..a71e443 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -471,6 +471,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n extern int index_name_is_other(const struct index_state *, const char *, int);\n+extern void *read_index_data(const char *path, struct index_state *use_index);\n \n /* do stat comparison even if CE_VALID is true */\n #define CE_MATCH_IGNORE_VALID\t\t01\ndiff --git a/read-cache.c b/read-cache.c\nindex 5a9704f..39e3424 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1899,3 +1899,36 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n \t}\n \treturn 1;\n }\n+\n+void *read_index_data(const char *path, struct index_state *use_index)\n+{\n+\tint pos, len;\n+\tunsigned long sz;\n+\tenum object_type type;\n+\tvoid *data;\n+\tstruct index_state *istate = use_index ? use_index : &the_index;\n+\n+\tlen = strlen(path);\n+\tpos = index_name_pos(istate, path, len);\n+\tif (pos < 0) {\n+\t\t/*\n+\t\t * We might be in the middle of a merge, in which\n+\t\t * case we would read stage #2 (ours).\n+\t\t */\n+\t\tint i;\n+\t\tfor (i = -pos - 1;\n+\t\t     (pos < 0 && i < istate->cache_nr &&\n+\t\t      !strcmp(istate->cache[i]->name, path));\n+\t\t     i++)\n+\t\t\tif (ce_stage(istate->cache[i]) == 2)\n+\t\t\t\tpos = i;\n+\t}\n+\tif (pos < 0)\n+\t\treturn NULL;\n+\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n+\tif (!data || type != OBJ_BLOB) {\n+\t\tfree(data);\n+\t\treturn NULL;\n+\t}\n+\treturn data;\n+}\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214081","messageId":"1365787573-597-3-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365787573-597-1-git-send-email-git@cryptocrack.de","subject":"[PATCH 2/3] Add size parameter to read_index_data()","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-12T17:26:12Z","receivedAt":"2013-04-12T17:26:12Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"This allows for optionally getting the size of the returned data and\nwill be used in a follow-up patch.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n attr.c       | 2 +-\n cache.h      | 2 +-\n read-cache.c | 5 ++++-\n 3 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 2e1ce7b..e5af3c6 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n \tchar *buf, *sp;\n \tint lineno = 0;\n \n-\tbuf = read_index_data(path, use_index);\n+\tbuf = read_index_data(path, use_index, NULL);\n \tif (!buf)\n \t\treturn NULL;\n \ndiff --git a/cache.h b/cache.h\nindex a71e443..b281bbf 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -471,7 +471,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n extern int index_name_is_other(const struct index_state *, const char *, int);\n-extern void *read_index_data(const char *path, struct index_state *use_index);\n+extern void *read_index_data(const char *path, struct index_state *use_index, unsigned long *size);\n \n /* do stat comparison even if CE_VALID is true */\n #define CE_MATCH_IGNORE_VALID\t\t01\ndiff --git a/read-cache.c b/read-cache.c\nindex 39e3424..32dc471 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1900,7 +1900,8 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n \treturn 1;\n }\n \n-void *read_index_data(const char *path, struct index_state *use_index)\n+void *read_index_data(const char *path, struct index_state *use_index,\n+\t\t      unsigned long *size)\n {\n \tint pos, len;\n \tunsigned long sz;\n@@ -1930,5 +1931,7 @@ void *read_index_data(const char *path, struct index_state *use_index)\n \t\tfree(data);\n \t\treturn NULL;\n \t}\n+\tif (size)\n+\t\t*size = sz;\n \treturn data;\n }\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214080","messageId":"1365787573-597-4-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365787573-597-1-git-send-email-git@cryptocrack.de","subject":"[PATCH 3/3] convert.c: Remove duplicate code","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-12T17:26:13Z","receivedAt":"2013-04-12T17:26:13Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"has_cr_in_index() is an almost 1:1 copy of read_index_data() with some\nadditions. Invoke read_index_data() instead of using copy-pasted code.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n convert.c | 27 ++-------------------------\n 1 file changed, 2 insertions(+), 25 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 3520252..0d9f8a9 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -153,36 +153,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,\n \n static int has_cr_in_index(const char *path)\n {\n-\tint pos, len;\n \tunsigned long sz;\n-\tenum object_type type;\n \tvoid *data;\n \tint has_cr;\n-\tstruct index_state *istate = &the_index;\n \n-\tlen = strlen(path);\n-\tpos = index_name_pos(istate, path, len);\n-\tif (pos < 0) {\n-\t\t/*\n-\t\t * We might be in the middle of a merge, in which\n-\t\t * case we would read stage #2 (ours).\n-\t\t */\n-\t\tint i;\n-\t\tfor (i = -pos - 1;\n-\t\t     (pos < 0 && i < istate->cache_nr &&\n-\t\t      !strcmp(istate->cache[i]->name, path));\n-\t\t     i++)\n-\t\t\tif (ce_stage(istate->cache[i]) == 2)\n-\t\t\t\tpos = i;\n-\t}\n-\tif (pos < 0)\n+\tdata = read_index_data(path, NULL, &sz);\n+\tif (!data)\n \t\treturn 0;\n-\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n-\tif (!data || type != OBJ_BLOB) {\n-\t\tfree(data);\n-\t\treturn 0;\n-\t}\n-\n \thas_cr = memchr(data, '\\r', sz) != NULL;\n \tfree(data);\n \treturn has_cr;\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214096","messageId":"20130412194012.GA5154@sigill.intra.peff.net","threadId":"33492","inReplyTo":"1365787573-597-2-git-send-email-git@cryptocrack.de","subject":"Re: [PATCH 1/3] Make read_index_data() public","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-04-12T19:40:12Z","receivedAt":"2013-04-12T19:40:12Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Apr 12, 2013 at 07:26:11PM +0200, Lukas Fleischer wrote:\n\n> This allows for reusing the function in convert.c later.\n> \n> Also, move it from attr.c to read-cache.c and add a use_index parameter\n> to specify a custom index_state since we are no longer enable to access\n> the static use_index variable from attr.c.\n\nI'm all for removing duplicated code, but, but I think the name\n\"read_index_data\" is a bit misleading for a global function. I would\nexpect it to read data from the index (and the argument \"path\" does not\nhelp clarify that at all).\n\nCan we rename it read_blob_data_from_index_path() or something?\n\n-Peff\n"},{"id":"214129","messageId":"20130413082317.GA31894@blizzard","threadId":"33492","inReplyTo":"20130412194012.GA5154@sigill.intra.peff.net","subject":"Re: [PATCH 1/3] Make read_index_data() public","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-13T08:23:17Z","receivedAt":"2013-04-13T08:23:17Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"On Fri, Apr 12, 2013 at 03:40:12PM -0400, Jeff King wrote:\n> On Fri, Apr 12, 2013 at 07:26:11PM +0200, Lukas Fleischer wrote:\n> \n> > This allows for reusing the function in convert.c later.\n> > \n> > Also, move it from attr.c to read-cache.c and add a use_index parameter\n> > to specify a custom index_state since we are no longer enable to access\n> > the static use_index variable from attr.c.\n> \n> I'm all for removing duplicated code, but, but I think the name\n> \"read_index_data\" is a bit misleading for a global function. I would\n> expect it to read data from the index (and the argument \"path\" does not\n> help clarify that at all).\n> \n> Can we rename it read_blob_data_from_index_path() or something?\n\nPretty long function name... I agree that it is better to have a verbose\nfunction name instead of something short that gives a wrong impression\nof what the function does and I can't think of a shorter, yet\ndescriptive way to name the function.\n\nIf nobody comes up with an alternative suggestion, I will change it to\nread_blob_data_from_index_path() and resubmit.\n\n> \n> -Peff\n"},{"id":"214135","messageId":"1365859712-8400-1-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365787573-597-1-git-send-email-git@cryptocrack.de","subject":"[PATCH v2 1/3] Add public function read_blob_data_from_index_path()","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-13T13:28:30Z","receivedAt":"2013-04-13T13:28:30Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"* Make the read_index_data() function public, rename it to\n  read_blob_data_from_index_path() and move it from attr.c to\n  read-cache.c.\n\n* Add a use_index parameter to specify a custom index_state since we are\n  no longer enable to access the static use_index variable from attr.c.\n\nThis allows for reusing the function in convert.c later.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n attr.c       | 35 +----------------------------------\n cache.h      |  1 +\n read-cache.c | 34 ++++++++++++++++++++++++++++++++++\n 3 files changed, 36 insertions(+), 34 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 689bc2a..08347b6 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -381,46 +381,13 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)\n \treturn res;\n }\n \n-static void *read_index_data(const char *path)\n-{\n-\tint pos, len;\n-\tunsigned long sz;\n-\tenum object_type type;\n-\tvoid *data;\n-\tstruct index_state *istate = use_index ? use_index : &the_index;\n-\n-\tlen = strlen(path);\n-\tpos = index_name_pos(istate, path, len);\n-\tif (pos < 0) {\n-\t\t/*\n-\t\t * We might be in the middle of a merge, in which\n-\t\t * case we would read stage #2 (ours).\n-\t\t */\n-\t\tint i;\n-\t\tfor (i = -pos - 1;\n-\t\t     (pos < 0 && i < istate->cache_nr &&\n-\t\t      !strcmp(istate->cache[i]->name, path));\n-\t\t     i++)\n-\t\t\tif (ce_stage(istate->cache[i]) == 2)\n-\t\t\t\tpos = i;\n-\t}\n-\tif (pos < 0)\n-\t\treturn NULL;\n-\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n-\tif (!data || type != OBJ_BLOB) {\n-\t\tfree(data);\n-\t\treturn NULL;\n-\t}\n-\treturn data;\n-}\n-\n static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n {\n \tstruct attr_stack *res;\n \tchar *buf, *sp;\n \tint lineno = 0;\n \n-\tbuf = read_index_data(path);\n+\tbuf = read_blob_data_from_index_path(path, use_index);\n \tif (!buf)\n \t\treturn NULL;\n \ndiff --git a/cache.h b/cache.h\nindex ba5a47c..2a206aa 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -471,6 +471,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n extern int index_name_is_other(const struct index_state *, const char *, int);\n+extern void *read_blob_data_from_index_path(const char *path, struct index_state *use_index);\n \n /* do stat comparison even if CE_VALID is true */\n #define CE_MATCH_IGNORE_VALID\t\t01\ndiff --git a/read-cache.c b/read-cache.c\nindex 5a9704f..964ae26 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1899,3 +1899,37 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n \t}\n \treturn 1;\n }\n+\n+void *read_blob_data_from_index_path(const char *path,\n+\t\t\t\t     struct index_state *use_index)\n+{\n+\tint pos, len;\n+\tunsigned long sz;\n+\tenum object_type type;\n+\tvoid *data;\n+\tstruct index_state *istate = use_index ? use_index : &the_index;\n+\n+\tlen = strlen(path);\n+\tpos = index_name_pos(istate, path, len);\n+\tif (pos < 0) {\n+\t\t/*\n+\t\t * We might be in the middle of a merge, in which\n+\t\t * case we would read stage #2 (ours).\n+\t\t */\n+\t\tint i;\n+\t\tfor (i = -pos - 1;\n+\t\t     (pos < 0 && i < istate->cache_nr &&\n+\t\t      !strcmp(istate->cache[i]->name, path));\n+\t\t     i++)\n+\t\t\tif (ce_stage(istate->cache[i]) == 2)\n+\t\t\t\tpos = i;\n+\t}\n+\tif (pos < 0)\n+\t\treturn NULL;\n+\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n+\tif (!data || type != OBJ_BLOB) {\n+\t\tfree(data);\n+\t\treturn NULL;\n+\t}\n+\treturn data;\n+}\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214133","messageId":"1365859712-8400-2-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365859712-8400-1-git-send-email-git@cryptocrack.de","subject":"[PATCH v2 2/3] Add size parameter to read_blob_data_from_index_path()","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-13T13:28:31Z","receivedAt":"2013-04-13T13:28:31Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"This allows for optionally getting the size of the returned data and\nwill be used in a follow-up patch.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n attr.c       | 2 +-\n cache.h      | 2 +-\n read-cache.c | 5 ++++-\n 3 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 08347b6..17338c8 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n \tchar *buf, *sp;\n \tint lineno = 0;\n \n-\tbuf = read_blob_data_from_index_path(path, use_index);\n+\tbuf = read_blob_data_from_index_path(path, use_index, NULL);\n \tif (!buf)\n \t\treturn NULL;\n \ndiff --git a/cache.h b/cache.h\nindex 2a206aa..a5272f2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -471,7 +471,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n extern int index_name_is_other(const struct index_state *, const char *, int);\n-extern void *read_blob_data_from_index_path(const char *path, struct index_state *use_index);\n+extern void *read_blob_data_from_index_path(const char *path, struct index_state *use_index, unsigned long *size);\n \n /* do stat comparison even if CE_VALID is true */\n #define CE_MATCH_IGNORE_VALID\t\t01\ndiff --git a/read-cache.c b/read-cache.c\nindex 964ae26..547e98a 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1901,7 +1901,8 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n }\n \n void *read_blob_data_from_index_path(const char *path,\n-\t\t\t\t     struct index_state *use_index)\n+\t\t\t\t     struct index_state *use_index,\n+\t\t\t\t     unsigned long *size)\n {\n \tint pos, len;\n \tunsigned long sz;\n@@ -1931,5 +1932,7 @@ void *read_blob_data_from_index_path(const char *path,\n \t\tfree(data);\n \t\treturn NULL;\n \t}\n+\tif (size)\n+\t\t*size = sz;\n \treturn data;\n }\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214134","messageId":"1365859712-8400-3-git-send-email-git@cryptocrack.de","threadId":"33492","inReplyTo":"1365859712-8400-1-git-send-email-git@cryptocrack.de","subject":"[PATCH v2 3/3] convert.c: Remove duplicate code","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-13T13:28:32Z","receivedAt":"2013-04-13T13:28:32Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"has_cr_in_index() is an almost 1:1 copy of\nread_blob_data_from_index_path() with some additions. Invoke\nread_blob_data_from_index_path() instead of using copy-pasted code.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n convert.c | 27 ++-------------------------\n 1 file changed, 2 insertions(+), 25 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 3520252..a12bc78 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -153,36 +153,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,\n \n static int has_cr_in_index(const char *path)\n {\n-\tint pos, len;\n \tunsigned long sz;\n-\tenum object_type type;\n \tvoid *data;\n \tint has_cr;\n-\tstruct index_state *istate = &the_index;\n \n-\tlen = strlen(path);\n-\tpos = index_name_pos(istate, path, len);\n-\tif (pos < 0) {\n-\t\t/*\n-\t\t * We might be in the middle of a merge, in which\n-\t\t * case we would read stage #2 (ours).\n-\t\t */\n-\t\tint i;\n-\t\tfor (i = -pos - 1;\n-\t\t     (pos < 0 && i < istate->cache_nr &&\n-\t\t      !strcmp(istate->cache[i]->name, path));\n-\t\t     i++)\n-\t\t\tif (ce_stage(istate->cache[i]) == 2)\n-\t\t\t\tpos = i;\n-\t}\n-\tif (pos < 0)\n+\tdata = read_blob_data_from_index_path(path, NULL, &sz);\n+\tif (!data)\n \t\treturn 0;\n-\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n-\tif (!data || type != OBJ_BLOB) {\n-\t\tfree(data);\n-\t\treturn 0;\n-\t}\n-\n \thas_cr = memchr(data, '\\r', sz) != NULL;\n \tfree(data);\n \treturn has_cr;\n-- \n1.8.2.675.gda3bb24.dirty\n"},{"id":"214156","messageId":"7vwqs56418.fsf@alter.siamese.dyndns.org","threadId":"33492","inReplyTo":"1365859712-8400-1-git-send-email-git@cryptocrack.de","subject":"Re: [PATCH v2 1/3] Add public function read_blob_data_from_index_path()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-14T05:49:36Z","receivedAt":"2013-04-14T05:49:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks. I'll queue with the following API fix-up on this, with\nobvious adjustments necessary for the later ones.\n\n * read_blob_data_from_index() is descriptive enough. If you read a\n   blob from the index, you would ask for it with a path; there is\n   no other sensible key to do so.\n\n * A function in read-cache API that works on an index should have\n   the istate as the first argument and called with name \"index\";\n\n * If callers want to operate on the default index, macro with a\n   similar name but replacing \"index\" with \"cache\" can be supplied,\n   e.g.\n\n   #define distim_cache(x) distim_index(&the_index, x)\n---\n attr.c       | 2 +-\n cache.h      | 3 ++-\n read-cache.c | 4 +---\n 3 files changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex a668a63..46bde57 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n \tchar *buf, *sp;\n \tint lineno = 0;\n \n-\tbuf = read_blob_data_from_index_path(path, use_index);\n+\tbuf = read_blob_data_from_index(use_index, path);\n \tif (!buf)\n \t\treturn NULL;\n \ndiff --git a/cache.h b/cache.h\nindex 85ddb13..5d66c74 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -307,6 +307,7 @@ extern void free_name_hash(struct index_state *istate);\n #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n+#define read_blob_data_from_cache(path) read_blob_data_from_index(&the_index, (path))\n #endif\n \n enum object_type {\n@@ -452,7 +453,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n extern int index_name_is_other(const struct index_state *, const char *, int);\n-extern void *read_blob_data_from_index_path(const char *path, struct index_state *use_index);\n+extern void *read_blob_data_from_index(struct index_state *, const char *);\n \n /* do stat comparison even if CE_VALID is true */\n #define CE_MATCH_IGNORE_VALID\t\t01\ndiff --git a/read-cache.c b/read-cache.c\nindex cbeb248..48d87e8 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1896,14 +1896,12 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n \treturn 1;\n }\n \n-void *read_blob_data_from_index_path(const char *path,\n-\t\t\t\t     struct index_state *use_index)\n+void *read_blob_data_from_index(struct index_state *istate, const char *path)\n {\n \tint pos, len;\n \tunsigned long sz;\n \tenum object_type type;\n \tvoid *data;\n-\tstruct index_state *istate = use_index ? use_index : &the_index;\n \n \tlen = strlen(path);\n \tpos = index_name_pos(istate, path, len);\n-- \n1.8.2.1-514-gf369d36\n"},{"id":"214157","messageId":"7vsj2t61ox.fsf@alter.siamese.dyndns.org","threadId":"33492","inReplyTo":"7vwqs56418.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 1/3] Add public function read_blob_data_from_index_path()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-14T06:55:42Z","receivedAt":"2013-04-14T06:55:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> diff --git a/attr.c b/attr.c\n> index a668a63..46bde57 100644\n> --- a/attr.c\n> +++ b/attr.c\n> @@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n>  \tchar *buf, *sp;\n>  \tint lineno = 0;\n>  \n> -\tbuf = read_blob_data_from_index_path(path, use_index);\n> +\tbuf = read_blob_data_from_index(use_index, path);\n\nThis was wrong.\n\nThe one I'll push out will have:\n\n\tbuf = read_blob_data_from_index(use_index ? use_index : &the_index, path);\n"},{"id":"214232","messageId":"20130414201415.GA9683@blizzard","threadId":"33492","inReplyTo":"7vwqs56418.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 1/3] Add public function read_blob_data_from_index_path()","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-04-14T20:14:15Z","receivedAt":"2013-04-14T20:14:15Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"On Sat, Apr 13, 2013 at 10:49:36PM -0700, Junio C Hamano wrote:\n> Thanks. I'll queue with the following API fix-up on this, with\n> obvious adjustments necessary for the later ones.\n> \n>  * read_blob_data_from_index() is descriptive enough. If you read a\n>    blob from the index, you would ask for it with a path; there is\n>    no other sensible key to do so.\n> \n>  * A function in read-cache API that works on an index should have\n>    the istate as the first argument and called with name \"index\";\n> \n>  * If callers want to operate on the default index, macro with a\n>    similar name but replacing \"index\" with \"cache\" can be supplied,\n>    e.g.\n> \n>    #define distim_cache(x) distim_index(&the_index, x)\n> ---\n>  attr.c       | 2 +-\n>  cache.h      | 3 ++-\n>  read-cache.c | 4 +---\n>  3 files changed, 4 insertions(+), 5 deletions(-)\n\nSounds reasonable to me -- squashing the fixed up version into my\noriginal patch ([PATCH v2 1/1] Add public function\nread_blob_data_from_index_path()) probably makes sense here :)\n\nThanks for reviewing and reworking!\n\n> \n> diff --git a/attr.c b/attr.c\n> index a668a63..46bde57 100644\n> --- a/attr.c\n> +++ b/attr.c\n> @@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)\n>  \tchar *buf, *sp;\n>  \tint lineno = 0;\n>  \n> -\tbuf = read_blob_data_from_index_path(path, use_index);\n> +\tbuf = read_blob_data_from_index(use_index, path);\n>  \tif (!buf)\n>  \t\treturn NULL;\n>  \n> diff --git a/cache.h b/cache.h\n> index 85ddb13..5d66c74 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -307,6 +307,7 @@ extern void free_name_hash(struct index_state *istate);\n>  #define resolve_undo_clear() resolve_undo_clear_index(&the_index)\n>  #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)\n>  #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)\n> +#define read_blob_data_from_cache(path) read_blob_data_from_index(&the_index, (path))\n>  #endif\n>  \n>  enum object_type {\n> @@ -452,7 +453,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);\n>  extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);\n>  extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);\n>  extern int index_name_is_other(const struct index_state *, const char *, int);\n> -extern void *read_blob_data_from_index_path(const char *path, struct index_state *use_index);\n> +extern void *read_blob_data_from_index(struct index_state *, const char *);\n>  \n>  /* do stat comparison even if CE_VALID is true */\n>  #define CE_MATCH_IGNORE_VALID\t\t01\n> diff --git a/read-cache.c b/read-cache.c\n> index cbeb248..48d87e8 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -1896,14 +1896,12 @@ int index_name_is_other(const struct index_state *istate, const char *name,\n>  \treturn 1;\n>  }\n>  \n> -void *read_blob_data_from_index_path(const char *path,\n> -\t\t\t\t     struct index_state *use_index)\n> +void *read_blob_data_from_index(struct index_state *istate, const char *path)\n>  {\n>  \tint pos, len;\n>  \tunsigned long sz;\n>  \tenum object_type type;\n>  \tvoid *data;\n> -\tstruct index_state *istate = use_index ? use_index : &the_index;\n>  \n>  \tlen = strlen(path);\n>  \tpos = index_name_pos(istate, path, len);\n> -- \n> 1.8.2.1-514-gf369d36\n> \n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}