Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/queue.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <zlib.h>
23 #include <sha1.h>
25 #include "got_error.h"
26 #include "got_repository.h"
27 #include "got_object.h"
29 #include "delta.h"
31 struct got_delta *
32 got_delta_open(const char *path_packfile, int type, off_t offset,
33 size_t size)
34 {
35 struct got_delta *delta;
37 delta = calloc(1, sizeof(*delta));
38 if (delta == NULL)
39 return NULL;
41 delta->path_packfile = strdup(path_packfile);
42 if (delta->path_packfile == NULL) {
43 free(delta);
44 return NULL;
45 }
46 delta->type = type;
47 delta->offset = offset;
48 delta->size = size;
49 return delta;
50 }
52 void
53 got_delta_close(struct got_delta *delta)
54 {
55 free(delta->path_packfile);
56 free(delta);
58 }
60 const struct got_error *
61 got_delta_chain_get_base_type(int *type, struct got_delta_chain *deltas)
62 {
63 struct got_delta *delta;
64 int n = 0;
66 /* Find the last delta in the chain. It should be a plain object. */
67 SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
68 n++;
69 if (delta->type == GOT_OBJ_TYPE_COMMIT ||
70 delta->type == GOT_OBJ_TYPE_TREE ||
71 delta->type == GOT_OBJ_TYPE_BLOB ||
72 delta->type == GOT_OBJ_TYPE_TAG) {
73 if (n != deltas->nentries)
74 return got_error(GOT_ERR_BAD_DELTA_CHAIN);
75 *type = delta->type;
76 return NULL;
77 }
78 }
80 return got_error(GOT_ERR_BAD_DELTA_CHAIN);
81 }
83 const struct got_error *
84 got_delta_apply(struct got_repository *repo, FILE *infile, size_t size,
85 struct got_object *base_obj, FILE *outfile)
86 {
87 return got_error(GOT_ERR_NOT_IMPL);
88 }