@matheusbsbs / matheus-bagliano / commits / 59c69c0c65
Fork 0

make alloc_ref_from_str() the new alloc_ref()

With all calls to alloc_ref() gone, we can remove it and then we're free to give alloc_ref_from_str() the shorter name. It's a much nicer interface, as the callers always need to have a name string when they allocate a ref anyway and don't need to calculate and pass its length+1 any more. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 18, 2008 at 10:44 UTC 59c69c0c656ebce2f7ce870b4913512597a98390
7 files changed +18 -27
builtin-fetch.c
+2 -2
@@ -521,8 +521,8 @@ static void find_non_local_tags(struct transport *transport,
521 will_fetch(head, ref->old_sha1))) {
522 string_list_insert(ref_name, &new_refs);
523
524 - rm = alloc_ref_from_str(ref_name);
525 - rm->peer_ref = alloc_ref_from_str(ref_name);
524 + rm = alloc_ref(ref_name);
525 + rm->peer_ref = alloc_ref(ref_name);
526 hashcpy(rm->old_sha1, ref_sha1);
527
528 **tail = rm;
connect.c
+1 -1
@@ -90,7 +90,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
90 continue;
91 if (nr_match && !path_match(name, nr_match, match))
92 continue;
93 - ref = alloc_ref_from_str(buffer + 41);
93 + ref = alloc_ref(buffer + 41);
94 hashcpy(ref->old_sha1, old_sha1);
95 *list = ref;
96 list = &ref->next;
http-push.c
+2 -2
@@ -1780,7 +1780,7 @@ static void one_remote_ref(char *refname)
1780 struct ref *ref;
1781 struct object *obj;
1782
1783 - ref = alloc_ref_from_str(refname);
1783 + ref = alloc_ref(refname);
1784
1785 if (http_fetch_ref(remote->url, ref) != 0) {
1786 fprintf(stderr,
@@ -1887,7 +1887,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1887 char *ref_info;
1888 struct ref *ref;
1889
1890 - ref = alloc_ref_from_str(ls->dentry_name);
1890 + ref = alloc_ref(ls->dentry_name);
1891
1892 if (http_fetch_ref(remote->url, ref) != 0) {
1893 fprintf(stderr,
remote.c
+7 -14
@@ -759,15 +759,9 @@ static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
759 return ref;
760 }
761
762 -struct ref *alloc_ref(unsigned namelen)
762 +struct ref *alloc_ref(const char *name)
763 {
764 - struct ref *ret = xcalloc(1, sizeof(struct ref) + namelen);
765 - return ret;
766 -}
767 -
768 -struct ref *alloc_ref_from_str(const char* str)
769 -{
770 - return alloc_ref_with_prefix("", 0, str);
764 + return alloc_ref_with_prefix("", 0, name);
765 }
766
767 static struct ref *copy_ref(const struct ref *ref)
@@ -878,20 +872,20 @@ static struct ref *try_explicit_object_name(const char *name)
872 struct ref *ref;
873
874 if (!*name) {
881 - ref = alloc_ref_from_str("(delete)");
875 + ref = alloc_ref("(delete)");
876 hashclr(ref->new_sha1);
877 return ref;
878 }
879 if (get_sha1(name, sha1))
880 return NULL;
887 - ref = alloc_ref_from_str(name);
881 + ref = alloc_ref(name);
882 hashcpy(ref->new_sha1, sha1);
883 return ref;
884 }
885
886 static struct ref *make_linked_ref(const char *name, struct ref ***tail)
887 {
894 - struct ref *ret = alloc_ref_from_str(name);
888 + struct ref *ret = alloc_ref(name);
889 tail_link_ref(ret, tail);
890 return ret;
891 }
@@ -1196,9 +1190,8 @@ static struct ref *get_local_ref(const char *name)
1190 if (!name)
1191 return NULL;
1192
1199 - if (!prefixcmp(name, "refs/")) {
1200 - return alloc_ref_from_str(name);
1201 - }
1193 + if (!prefixcmp(name, "refs/"))
1194 + return alloc_ref(name);
1195
1196 if (!prefixcmp(name, "heads/") ||
1197 !prefixcmp(name, "tags/") ||
remote.h
+1 -3
@@ -55,9 +55,7 @@ struct refspec {
55
56 extern const struct refspec *tag_refspec;
57
58 -struct ref *alloc_ref(unsigned namelen);
59 -
60 -struct ref *alloc_ref_from_str(const char* str);
58 +struct ref *alloc_ref(const char *name);
59
60 struct ref *copy_ref_list(const struct ref *ref);
61
transport.c
+4 -4
@@ -75,7 +75,7 @@ static int read_loose_refs(struct strbuf *path, int name_offset,
75
76 if (fd < 0)
77 continue;
78 - next = alloc_ref_from_str(path->buf + name_offset);
78 + next = alloc_ref(path->buf + name_offset);
79 if (read_in_full(fd, buffer, 40) != 40 ||
80 get_sha1_hex(buffer, next->old_sha1)) {
81 close(fd);
@@ -126,7 +126,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
126 (*list)->next->name)) > 0)
127 list = &(*list)->next;
128 if (!(*list)->next || cmp < 0) {
129 - struct ref *next = alloc_ref_from_str(buffer + 41);
129 + struct ref *next = alloc_ref(buffer + 41);
130 buffer[40] = '\0';
131 if (get_sha1_hex(buffer, next->old_sha1)) {
132 warning ("invalid SHA-1: %s", buffer);
@@ -499,7 +499,7 @@ static struct ref *get_refs_via_curl(struct transport *transport)
499
500 strbuf_release(&buffer);
501
502 - ref = alloc_ref_from_str("HEAD");
502 + ref = alloc_ref("HEAD");
503 if (!walker->fetch_ref(walker, ref) &&
504 !resolve_remote_symref(ref, refs)) {
505 ref->next = refs;
@@ -540,7 +540,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport)
540 die ("Could not read bundle '%s'.", transport->url);
541 for (i = 0; i < data->header.references.nr; i++) {
542 struct ref_list_entry *e = data->header.references.list + i;
543 - struct ref *ref = alloc_ref_from_str(e->name);
543 + struct ref *ref = alloc_ref(e->name);
544 hashcpy(ref->old_sha1, e->sha1);
545 ref->next = result;
546 result = ref;
walker.c
+1 -1
@@ -191,7 +191,7 @@ static int interpret_target(struct walker *walker, char *target, unsigned char *
191 if (!get_sha1_hex(target, sha1))
192 return 0;
193 if (!check_ref_format(target)) {
194 - struct ref *ref = alloc_ref_from_str(target);
194 + struct ref *ref = alloc_ref(target);
195 if (!walker->fetch_ref(walker, ref)) {
196 hashcpy(sha1, ref->old_sha1);
197 free(ref);