add some stub code for packed ref-delta objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
diff --git a/lib/delta.c b/lib/delta.c
new file mode 100644
index 0000000..d7921f1
--- /dev/null
+++ b/lib/delta.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 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 <sys/queue.h>
+
+#include <stdio.h>
+#include <zlib.h>
+#include <sha1.h>
+
+#include "got_error.h"
+#include "got_repository.h"
+#include "got_object.h"
+
+#include "delta.h"
+
+const struct got_error *
+got_delta_apply(struct got_repository *repo, FILE *infile, size_t size,
+ struct got_object *base_obj, FILE *outfile)
+{
+ return got_error(GOT_ERR_NOT_IMPL);
+}
diff --git a/lib/delta.h b/lib/delta.h
new file mode 100644
index 0000000..88d8a5d
--- /dev/null
+++ b/lib/delta.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+const struct got_error *
+got_delta_apply(struct got_repository *, FILE *, size_t, struct got_object *,
+ FILE *);
diff --git a/lib/pack.c b/lib/pack.c
index b7ef020..c4087fb 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -35,6 +35,7 @@
#include "got_sha1.h"
#include "pack.h"
#include "path.h"
+#include "delta.h"
#define GOT_PACK_PREFIX "pack-"
#define GOT_PACKFILE_SUFFIX ".pack"
@@ -515,11 +516,11 @@ dump_plain_object(FILE *infile, uint8_t type, size_t size, FILE *outfile)
n = fread(data, len, 1, infile);
if (n != 1)
- return got_ferror(infile, GOT_ERR_BAD_PACKIDX);
+ return got_ferror(infile, GOT_ERR_BAD_PACKFILE);
n = fwrite(data, len, 1, outfile);
if (n != 1)
- return got_ferror(outfile, GOT_ERR_BAD_PACKIDX);
+ return got_ferror(outfile, GOT_ERR_IO);
size -= len;
}
@@ -528,6 +529,35 @@ dump_plain_object(FILE *infile, uint8_t type, size_t size, FILE *outfile)
return NULL;
}
+static const struct got_error *
+dump_ref_delta_object(struct got_repository *repo, FILE *infile, uint8_t type,
+ size_t size, FILE *outfile)
+{
+ const struct got_error *err = NULL;
+ struct got_object_id base_id;
+ struct got_object *base_obj;
+ int n;
+
+ if (size < sizeof(base_id))
+ return got_ferror(infile, GOT_ERR_BAD_PACKFILE);
+
+ n = fread(&base_id, sizeof(base_id), 1, infile);
+ if (n != 1)
+ return got_ferror(infile, GOT_ERR_BAD_PACKFILE);
+
+ size -= sizeof(base_id);
+ if (size <= 0)
+ return got_ferror(infile, GOT_ERR_BAD_PACKFILE);
+
+ err = got_object_open(&base_obj, repo, &base_id);
+ if (err)
+ return err;
+
+ err = got_delta_apply(repo, infile, size, base_obj, outfile);
+ got_object_close(base_obj);
+ return err;
+}
+
const struct got_error *
got_packfile_extract_object(FILE **f, struct got_object *obj,
struct got_repository *repo)
@@ -562,6 +592,9 @@ got_packfile_extract_object(FILE **f, struct got_object *obj,
err = dump_plain_object(packfile, obj->type, obj->size, *f);
break;
case GOT_OBJ_TYPE_REF_DELTA:
+ err = dump_ref_delta_object(repo, packfile, obj->type,
+ obj->size, *f);
+ break;
case GOT_OBJ_TYPE_TAG:
case GOT_OBJ_TYPE_OFFSET_DELTA:
default:
diff --git a/regress/repository/Makefile b/regress/repository/Makefile
index 5ed8a9e..c506dc7 100644
--- a/regress/repository/Makefile
+++ b/regress/repository/Makefile
@@ -2,7 +2,7 @@
PROG = repository_test
SRCS = path.c repository.c error.c refs.c object.c sha1.c diff.c \
- diffreg.c xmalloc.c pack.c repository_test.c
+ diffreg.c xmalloc.c pack.c delta.c repository_test.c
CPPFLAGS = -I${.CURDIR}/../../include
LDADD = -lutil -lz