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;
65 /* The first delta in the chain should represent the base object. */
66 delta = SIMPLEQ_FIRST(&deltas->entries);
67 if (delta->type == GOT_OBJ_TYPE_COMMIT ||
68 delta->type == GOT_OBJ_TYPE_TREE ||
69 delta->type == GOT_OBJ_TYPE_BLOB ||
70 delta->type == GOT_OBJ_TYPE_TAG) {
71 *type = delta->type;
72 return NULL;
73 }
75 return got_error(GOT_ERR_BAD_DELTA_CHAIN);
76 }
78 const struct got_error *got_delta_apply(struct got_delta *delta,
79 FILE *base_file, FILE *delta_file, FILE *outfile)
80 {
81 return got_error(GOT_ERR_NOT_IMPL);
82 }