commit - d4a5a8855b74b1a8d44747715e9545e53d7e6634
commit + d71d75ad16058715e286e90bf48ab4f3d76e2127
blob - eeca74e22721ef756289ffa1d8fa2578b8bb99c4
blob + fdfff2e90cf197c3377cf3a2df9b005075469071
--- include/got_object.h
+++ include/got_object.h
struct got_object_id {
u_int8_t sha1[SHA1_DIGEST_LENGTH];
};
+
+const char * got_object_id_str(struct got_object_id *, char *, size_t);
blob - /dev/null
blob + 4e9d9cfc4245c5c928a8abeb20463300b7469393 (mode 644)
--- /dev/null
+++ lib/object.c
+/*
+ * Copyright (c) 2017 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <sha1.h>
+
+#include "got_object.h"
+
+const char *
+got_object_id_str(struct got_object_id *id, char *buf, size_t size)
+{
+ char *p = buf;
+ char hex[3];
+ int i;
+
+ if (size < SHA1_DIGEST_STRING_LENGTH)
+ return NULL;
+
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ snprintf(hex, sizeof(hex), "%.2x", id->sha1[i]);
+ p[0] = hex[0];
+ p[1] = hex[1];
+ p += 2;
+ }
+ p[0] = '\0';
+
+ return buf;
+}
blob - 141f5fdc96126c1f4195558560a3c915e3d9b4c3
blob + 4a4a51ff51f09e461601809905d6eb6f3ec619a0
--- regress/repository/Makefile
+++ regress/repository/Makefile
.PATH:${.CURDIR}/../../lib
PROG = repository_test
-SRCS = path.c repository.c error.c refs.c repository_test.c
+SRCS = path.c repository.c error.c refs.c object.c repository_test.c
CPPFLAGS = -I${.CURDIR}/../../include
LDADD = -lutil
blob - 7734cd5d7c756e596111defd73a5d42fb42a22f8
blob + eb48aeca9c322748e88fc2cc83d9ad58b86c98d3
--- regress/repository/repository_test.c
+++ regress/repository/repository_test.c
struct got_repository *repo;
struct got_reference *head_ref;
struct got_object_id *id;
+ char buf[SHA1_DIGEST_STRING_LENGTH];
int ret;
err = got_repo_open(&repo, repo_path);
err = got_ref_resolve(&id, repo, head_ref);
if (err != NULL || head_ref == NULL)
return 0;
+ printf("HEAD is at %s\n", got_object_id_str(id, buf, sizeof(buf)));
free(id);
got_ref_close(head_ref);
got_repo_close(repo);