diff mbox series

[15/31] builtin/pull: make hash-size independent

Message ID 20190212012256.1005924-16-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series Hash function transition part 16 | expand

Commit Message

brian m. carlson Feb. 12, 2019, 1:22 a.m. UTC
Instead of using get_oid_hex and GIT_SHA1_HEXSZ, use parse_oid_hex to
avoid the need for a constant and simplify the code.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/pull.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Sunshine Feb. 12, 2019, 3:47 a.m. UTC | #1
On Mon, Feb 11, 2019 at 8:23 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> Instead of using get_oid_hex and GIT_SHA1_HEXSZ, use parse_oid_hex to
> avoid the need for a constant and simplify the code.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/builtin/pull.c b/builtin/pull.c
> @@ -365,9 +365,10 @@ static void get_merge_heads(struct oid_array *merge_heads)
>         while (strbuf_getline_lf(&sb, fp) != EOF) {
> -               if (get_oid_hex(sb.buf, &oid))
> +               const char *p;
> +               if (parse_oid_hex(sb.buf, &oid, &p))
>                         continue;  /* invalid line: does not start with SHA1 */

While you're here, perhaps fix the comment so it doesn't talk about
SHA1 anymore.

> -               if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
> +               if (starts_with(p, "\tnot-for-merge\t"))
>                         continue;  /* ref is not-for-merge */
>                 oid_array_append(merge_heads, &oid);
>         }
diff mbox series

Patch

diff --git a/builtin/pull.c b/builtin/pull.c
index 701d1473dc..52d93c1e3b 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -365,9 +365,10 @@  static void get_merge_heads(struct oid_array *merge_heads)
 
 	fp = xfopen(filename, "r");
 	while (strbuf_getline_lf(&sb, fp) != EOF) {
-		if (get_oid_hex(sb.buf, &oid))
+		const char *p;
+		if (parse_oid_hex(sb.buf, &oid, &p))
 			continue;  /* invalid line: does not start with SHA1 */
-		if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
+		if (starts_with(p, "\tnot-for-merge\t"))
 			continue;  /* ref is not-for-merge */
 		oid_array_append(merge_heads, &oid);
 	}