From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/3] use alloc_ref_from_str() everywhere
Date: Sat, 18 Oct 2008 10:41:33 +0200 [thread overview]
Message-ID: <48F9A13D.3090401@lsrfire.ath.cx> (raw)
In-Reply-To: <48F9A054.4010703@lsrfire.ath.cx>
Replace pairs of alloc_ref() and strcpy() with alloc_ref_from_str(),
simplifying the code.
In connect.c, also a pair of alloc_ref() and memcpy() is replaced --
the additional cost of a strlen() call should not have too much of an
impact. Consistency and simplicity are more important.
In remote.c, the code was allocating 11 bytes more than needed for
the name part, but I couldn't see them being used for anything.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
connect.c | 3 +--
remote.c | 3 +--
transport.c | 6 ++----
3 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/connect.c b/connect.c
index 67d2cd8..b69060b 100644
--- a/connect.c
+++ b/connect.c
@@ -90,9 +90,8 @@ struct ref **get_remote_heads(int in, struct ref **list,
continue;
if (nr_match && !path_match(name, nr_match, match))
continue;
- ref = alloc_ref(name_len + 1);
+ ref = alloc_ref_from_str(buffer + 41);
hashcpy(ref->old_sha1, old_sha1);
- memcpy(ref->name, buffer + 41, name_len + 1);
*list = ref;
list = &ref->next;
}
diff --git a/remote.c b/remote.c
index 98cbcf9..44d681d 100644
--- a/remote.c
+++ b/remote.c
@@ -878,8 +878,7 @@ static struct ref *try_explicit_object_name(const char *name)
struct ref *ref;
if (!*name) {
- ref = alloc_ref(20);
- strcpy(ref->name, "(delete)");
+ ref = alloc_ref_from_str("(delete)");
hashclr(ref->new_sha1);
return ref;
}
diff --git a/transport.c b/transport.c
index 5110c56..3d03475 100644
--- a/transport.c
+++ b/transport.c
@@ -75,15 +75,14 @@ static int read_loose_refs(struct strbuf *path, int name_offset,
if (fd < 0)
continue;
- next = alloc_ref(path->len - name_offset + 1);
+ next = alloc_ref_from_str(path->buf + name_offset);
if (read_in_full(fd, buffer, 40) != 40 ||
get_sha1_hex(buffer, next->old_sha1)) {
close(fd);
free(next);
continue;
}
close(fd);
- strcpy(next->name, path->buf + name_offset);
(*tail)->next = next;
*tail = next;
}
@@ -127,14 +126,13 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
(*list)->next->name)) > 0)
list = &(*list)->next;
if (!(*list)->next || cmp < 0) {
- struct ref *next = alloc_ref(len - 40);
+ struct ref *next = alloc_ref_from_str(buffer + 41);
buffer[40] = '\0';
if (get_sha1_hex(buffer, next->old_sha1)) {
warning ("invalid SHA-1: %s", buffer);
free(next);
continue;
}
- strcpy(next->name, buffer + 41);
next->next = (*list)->next;
(*list)->next = next;
list = &(*list)->next;
--
1.6.0.2.542.gde55
next prev parent reply other threads:[~2008-10-18 8:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-18 8:37 [PATCH 1/3] add alloc_ref_with_prefix() René Scharfe
2008-10-18 8:41 ` René Scharfe [this message]
2008-10-18 8:44 ` [PATCH 3/3] make alloc_ref_from_str() the new alloc_ref() René Scharfe
2008-10-18 9:27 ` [PATCH 1/3] add alloc_ref_with_prefix() Bert Wesarg
2008-10-18 9:39 ` René Scharfe
2008-10-18 12:07 ` Bert Wesarg
2008-10-18 12:35 ` René Scharfe
2008-10-20 10:34 ` Andreas Ericsson
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=48F9A13D.3090401@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).