commit - c23ceb4705abfcbdf3cfe80862eccafb8b9975ef
commit + 661072277fe516d8c1289af46b7ab82a1e524e87
blob - f89933a7e7a1fa06d08e0f23b68887fcd4b41159
blob + db9381bb5a22e7386841403b87c3d2a98dc43ab5
--- lib/reference.c
+++ lib/reference.c
/* A non-symbolic reference (there is no better designation). */
struct got_ref {
char *name;
- u_int8_t sha1[SHA1_DIGEST_LENGTH];
+ struct got_object_id id;
};
/* A reference which points to an arbitrary object. */
if (*ref == NULL)
return got_error_from_errno("calloc");
- memcpy((*ref)->ref.ref.sha1, id->sha1, sizeof((*ref)->ref.ref.sha1));
+ memcpy(&(*ref)->ref.ref.id, id, sizeof((*ref)->ref.ref.id));
(*ref)->flags = flags;
(*ref)->ref.ref.name = strdup(name);
(*ref)->mtime = mtime;
free(ret);
return NULL;
}
- memcpy(ret->ref.ref.sha1, ref->ref.ref.sha1,
- sizeof(ret->ref.ref.sha1));
+ memcpy(&ret->ref.ref.id, &ref->ref.ref.id,
+ sizeof(ret->ref.ref.id));
}
return ret;
*id = calloc(1, sizeof(**id));
if (*id == NULL)
return got_error_from_errno("calloc");
- memcpy((*id)->sha1, ref->ref.ref.sha1, sizeof((*id)->sha1));
+ memcpy(*id, &ref->ref.ref.id, sizeof(**id));
return NULL;
}
if (ref->flags & GOT_REF_IS_SYMBOLIC)
return strdup(ref->ref.symref.ref);
- str = malloc(SHA1_DIGEST_STRING_LENGTH);
- if (str == NULL)
- return NULL;
-
- if (got_sha1_digest_to_str(ref->ref.ref.sha1, str,
- SHA1_DIGEST_STRING_LENGTH) == NULL) {
- free(str);
+ if (got_object_id_str(&str, &ref->ref.ref.id) != NULL)
return NULL;
- }
return str;
}
if (ref->flags & GOT_REF_IS_SYMBOLIC)
return got_error(GOT_ERR_BAD_REF_TYPE);
- memcpy(ref->ref.ref.sha1, id->sha1, sizeof(ref->ref.ref.sha1));
+ memcpy(&ref->ref.ref.id, id, sizeof(ref->ref.ref.id));
return NULL;
}
return got_error(GOT_ERR_BAD_REF_TYPE);
symref->ref.ref.name = symref->ref.symref.name;
- memcpy(symref->ref.ref.sha1, id->sha1, SHA1_DIGEST_LENGTH);
+ memcpy(&symref->ref.ref.id, id, sizeof(symref->ref.ref.id));
symref->flags &= ~GOT_REF_IS_SYMBOLIC;
return NULL;
}
goto done;
}
} else {
- char hex[SHA1_DIGEST_STRING_LENGTH];
- if (got_sha1_digest_to_str(ref->ref.ref.sha1, hex,
- sizeof(hex)) == NULL) {
- err = got_error(GOT_ERR_BAD_REF_DATA);
- goto done;
- }
+ char *hex;
+ size_t len;
+
+ err = got_object_id_str(&hex, &ref->ref.ref.id);
+ if (err)
+ goto done;
+ len = strlen(hex);
n = fprintf(f, "%s\n", hex);
- if (n != sizeof(hex)) {
+ free(hex);
+ if (n != len + 1) {
err = got_ferror(f, GOT_ERR_IO);
goto done;
}
continue;
if (strcmp(ref->ref.ref.name, delref->ref.ref.name) == 0 &&
- memcmp(ref->ref.ref.sha1, delref->ref.ref.sha1,
- sizeof(delref->ref.ref.sha1)) == 0) {
+ got_object_id_cmp(&ref->ref.ref.id,
+ &delref->ref.ref.id) == 0) {
found_delref = 1;
got_ref_close(ref);
continue;
}
TAILQ_FOREACH(re, &refs, entry) {
- char hex[SHA1_DIGEST_STRING_LENGTH];
+ char *hex;
+ size_t len;
- if (got_sha1_digest_to_str(re->ref->ref.ref.sha1, hex,
- sizeof(hex)) == NULL) {
- err = got_error(GOT_ERR_BAD_REF_DATA);
+ err = got_object_id_str(&hex, &re->ref->ref.ref.id);
+ if (err)
goto done;
- }
+ len = strlen(hex);
n = fprintf(tmpf, "%s ", hex);
- if (n != sizeof(hex)) {
+ free(hex);
+ if (n != len + 1) {
err = got_ferror(f, GOT_ERR_IO);
goto done;
}
+
n = fprintf(tmpf, "%s\n", re->ref->ref.ref.name);
if (n != strlen(re->ref->ref.ref.name) + 1) {
err = got_ferror(f, GOT_ERR_IO);