Blame


1 efd2a263 2018-01-19 stsp /*
2 efd2a263 2018-01-19 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 efd2a263 2018-01-19 stsp *
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.
7 efd2a263 2018-01-19 stsp *
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.
15 efd2a263 2018-01-19 stsp */
16 efd2a263 2018-01-19 stsp
17 efd2a263 2018-01-19 stsp #include <sys/queue.h>
18 efd2a263 2018-01-19 stsp
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>
24 efd2a263 2018-01-19 stsp
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"
28 efd2a263 2018-01-19 stsp
29 efd2a263 2018-01-19 stsp #include "delta.h"
30 efd2a263 2018-01-19 stsp
31 c3703302 2018-01-23 stsp struct got_delta *
32 c3703302 2018-01-23 stsp got_delta_open(const char *path_packfile, int type, off_t offset,
33 5a2e13f7 2018-01-23 stsp size_t size)
34 96f5e8b3 2018-01-23 stsp {
35 c3703302 2018-01-23 stsp struct got_delta *delta;
36 96f5e8b3 2018-01-23 stsp
37 c3703302 2018-01-23 stsp delta = calloc(1, sizeof(*delta));
38 c3703302 2018-01-23 stsp if (delta == NULL)
39 96f5e8b3 2018-01-23 stsp return NULL;
40 96f5e8b3 2018-01-23 stsp
41 c3703302 2018-01-23 stsp delta->path_packfile = strdup(path_packfile);
42 c3703302 2018-01-23 stsp if (delta->path_packfile == NULL) {
43 c3703302 2018-01-23 stsp free(delta);
44 96f5e8b3 2018-01-23 stsp return NULL;
45 96f5e8b3 2018-01-23 stsp }
46 c3703302 2018-01-23 stsp delta->type = type;
47 c3703302 2018-01-23 stsp delta->offset = offset;
48 c3703302 2018-01-23 stsp delta->size = size;
49 c3703302 2018-01-23 stsp return delta;
50 96f5e8b3 2018-01-23 stsp }
51 96f5e8b3 2018-01-23 stsp
52 96f5e8b3 2018-01-23 stsp void
53 c3703302 2018-01-23 stsp got_delta_close(struct got_delta *delta)
54 96f5e8b3 2018-01-23 stsp {
55 c3703302 2018-01-23 stsp free(delta->path_packfile);
56 c3703302 2018-01-23 stsp free(delta);
57 96f5e8b3 2018-01-23 stsp
58 96f5e8b3 2018-01-23 stsp }
59 96f5e8b3 2018-01-23 stsp
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)
62 96f5e8b3 2018-01-23 stsp {
63 c3703302 2018-01-23 stsp struct got_delta *delta;
64 96f5e8b3 2018-01-23 stsp int n = 0;
65 96f5e8b3 2018-01-23 stsp
66 c3703302 2018-01-23 stsp /* Find the last delta in the chain. It should be a plain object. */
67 c3703302 2018-01-23 stsp SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
68 96f5e8b3 2018-01-23 stsp n++;
69 c3703302 2018-01-23 stsp if (delta->type == GOT_OBJ_TYPE_COMMIT ||
70 c3703302 2018-01-23 stsp delta->type == GOT_OBJ_TYPE_TREE ||
71 c3703302 2018-01-23 stsp delta->type == GOT_OBJ_TYPE_BLOB ||
72 c3703302 2018-01-23 stsp delta->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 c3703302 2018-01-23 stsp *type = delta->type;
76 96f5e8b3 2018-01-23 stsp return NULL;
77 96f5e8b3 2018-01-23 stsp }
78 96f5e8b3 2018-01-23 stsp }
79 96f5e8b3 2018-01-23 stsp
80 96f5e8b3 2018-01-23 stsp return got_error(GOT_ERR_BAD_DELTA_CHAIN);
81 96f5e8b3 2018-01-23 stsp }
82 96f5e8b3 2018-01-23 stsp
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)
86 efd2a263 2018-01-19 stsp {
87 efd2a263 2018-01-19 stsp return got_error(GOT_ERR_NOT_IMPL);
88 efd2a263 2018-01-19 stsp }