From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH v2 06/10] get_remote_heads: convert to struct object_id
Date: Sat, 13 Jun 2015 22:16:39 +0000 [thread overview]
Message-ID: <1434233803-422442-7-git-send-email-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <1434233803-422442-1-git-send-email-sandals@crustytoothpaste.net>
Replace an unsigned char array with struct object_id and express several
hard-coded constants in terms of GIT_SHA1_HEXSZ.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
connect.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/connect.c b/connect.c
index f8b10eb..7f005a7 100644
--- a/connect.c
+++ b/connect.c
@@ -119,7 +119,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
*list = NULL;
for (;;) {
struct ref *ref;
- unsigned char old_sha1[20];
+ struct object_id old_oid;
char *name;
int len, name_len;
char *buffer = packet_buffer;
@@ -138,34 +138,36 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
die("remote error: %s", arg);
- if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
- if (get_sha1_hex(arg, old_sha1))
+ if (len == GIT_SHA1_HEXSZ + strlen("shallow ") &&
+ skip_prefix(buffer, "shallow ", &arg)) {
+ if (get_oid_hex(arg, &old_oid))
die("protocol error: expected shallow sha-1, got '%s'", arg);
if (!shallow_points)
die("repository on the other end cannot be shallow");
- sha1_array_append(shallow_points, old_sha1);
+ sha1_array_append(shallow_points, old_oid.hash);
continue;
}
- if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
+ if (len < GIT_SHA1_HEXSZ + 2 || get_oid_hex(buffer, &old_oid) ||
+ buffer[GIT_SHA1_HEXSZ] != ' ')
die("protocol error: expected sha/ref, got '%s'", buffer);
- name = buffer + 41;
+ name = buffer + GIT_SHA1_HEXSZ + 1;
name_len = strlen(name);
- if (len != name_len + 41) {
+ if (len != name_len + GIT_SHA1_HEXSZ + 1) {
free(server_capabilities);
server_capabilities = xstrdup(name + name_len + 1);
}
if (extra_have && !strcmp(name, ".have")) {
- sha1_array_append(extra_have, old_sha1);
+ sha1_array_append(extra_have, old_oid.hash);
continue;
}
if (!check_ref(name, flags))
continue;
- ref = alloc_ref(buffer + 41);
- hashcpy(ref->old_oid.hash, old_sha1);
+ ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
+ oidcpy(&ref->old_oid, &old_oid);
*list = ref;
list = &ref->next;
got_at_least_one_head = 1;
--
2.4.0
next prev parent reply other threads:[~2015-06-13 22:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
2015-06-13 22:16 ` [PATCH v2 01/10] refs: convert some internal functions to use object_id brian m. carlson
2015-06-13 22:16 ` [PATCH v2 02/10] sha1_file: introduce has_object_file helper brian m. carlson
2015-06-13 22:16 ` [PATCH v2 03/10] Convert struct ref to use object_id brian m. carlson
2015-06-15 22:13 ` Junio C Hamano
2015-06-13 22:16 ` [PATCH v2 04/10] add_sought_entry_mem: convert to struct object_id brian m. carlson
2015-06-13 22:16 ` [PATCH v2 05/10] parse_fetch: convert to use " brian m. carlson
2015-06-13 22:16 ` brian m. carlson [this message]
2015-06-13 22:16 ` [PATCH v2 07/10] push_refs_with_export: convert to " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 08/10] ref_newer: convert to use " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 10/10] remote: convert functions to " brian m. carlson
2015-08-02 23:33 ` [PATCH v2 00/10] object_id part 2 Michael Haggerty
2015-08-03 23:45 ` brian m. carlson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434233803-422442-7-git-send-email-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).