commit - bbcf6d65ac8203f4ec3edc715a5261ec61234539
commit + efd2a263f541b0617f5acd893f91f73edb07e84d
blob - /dev/null
blob + d7921f101a80ac0e5ff01abfb10b96c552c42d31 (mode 644)
--- /dev/null
+++ lib/delta.c
+/*
+ * 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);
+}
blob - /dev/null
blob + 88d8a5df95209ae177089165c92a4ca8cb03fc70 (mode 644)
--- /dev/null
+++ lib/delta.h
+/*
+ * 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 *);
blob - b7ef020f8e98efb339651e6719d66a5361c8b0f6
blob + c4087fbe7e8f6e3152cb28c188ec95e639687690
--- lib/pack.c
+++ lib/pack.c
#include "got_sha1.h"
#include "pack.h"
#include "path.h"
+#include "delta.h"
#define GOT_PACK_PREFIX "pack-"
#define GOT_PACKFILE_SUFFIX ".pack"
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;
}
rewind(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)
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:
blob - 5ed8a9e45330f0883681095cf5139a08ecc7f03f
blob + c506dc70c054f39ca5b85a1a9b63d7ad956368d3
--- regress/repository/Makefile
+++ regress/repository/Makefile
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