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