[PATCH v2 09/10] mktree: stop setting *ntr++ to NIL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since 58ce21b819e (builtin/mktree: remove hard-coded constant,
2018-10-15) we have not made any subsequent use of the ntr variable
itself, but we did rely on it to NIL-delimit the string we were about
to feed to type_from_string().

Using type_from_string() here results in needless work, as we'd do a
strlen() on it, just to find point at which we had a SPC
character (now NIL) earlier in this function.

We can instead skip incrementing the ntr pointer, then pass the
pointer and length to the type_from_string() function instead.

Doing so would have been buggy in cases where the type was invalid
until a preceding commit fixed the die() invocation in
type_from_string() to also pay attention to the length. A preceding
commit added a test to t1010-mktree.sh which would fail if not for
that fix in type_from_string(), i.e. we'd end up printing the rest of
the line, not just the invalid type.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 builtin/mktree.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/builtin/mktree.c b/builtin/mktree.c
index 891991b00d..7a27cfa2e0 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -95,9 +95,6 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
 	if (S_ISGITLINK(mode))
 		allow_missing = 1;
 
-
-	*ntr++ = 0; /* now at the beginning of SHA1 */
-
 	path = (char *)p + 1;  /* at the beginning of name */
 	if (!nul_term_line && path[0] == '"') {
 		struct strbuf p_uq = STRBUF_INIT;
@@ -111,7 +108,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
 	 * These should all agree.
 	 */
 	mode_type = object_type(mode);
-	if (mode_type != type_from_string(ptr)) {
+	if (mode_type != type_from_string_gently(ptr, ntr - ptr, 0)) {
 		die("entry '%s' object type (%s) doesn't match mode type (%s)",
 			path, ptr, type_name(mode_type));
 	}
-- 
2.31.1.723.ga5d7868e4a




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux