2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
4 c48c4a9c 2018-03-11 stsp * Permission to use, copy, modify, and distribute this software for any
5 c48c4a9c 2018-03-11 stsp * purpose with or without fee is hereby granted, provided that the above
6 c48c4a9c 2018-03-11 stsp * copyright notice and this permission notice appear in all copies.
8 c48c4a9c 2018-03-11 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 c48c4a9c 2018-03-11 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 c48c4a9c 2018-03-11 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 c48c4a9c 2018-03-11 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 c48c4a9c 2018-03-11 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 c48c4a9c 2018-03-11 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 c48c4a9c 2018-03-11 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c48c4a9c 2018-03-11 stsp #include <sys/queue.h>
18 133d2798 2019-01-08 stsp #include <sys/tree.h>
19 c48c4a9c 2018-03-11 stsp #include <sys/stat.h>
21 d1f6d47b 2019-02-04 stsp #include <dirent.h>
22 c48c4a9c 2018-03-11 stsp #include <stdio.h>
23 c48c4a9c 2018-03-11 stsp #include <stdlib.h>
24 c48c4a9c 2018-03-11 stsp #include <string.h>
25 c48c4a9c 2018-03-11 stsp #include <sha1.h>
26 c34b20a2 2018-03-12 stsp #include <endian.h>
27 133d2798 2019-01-08 stsp #include <limits.h>
28 c442a90d 2019-03-10 stsp #include <uuid.h>
30 c48c4a9c 2018-03-11 stsp #include "got_error.h"
31 8da9e5f4 2019-01-12 stsp #include "got_object.h"
33 133d2798 2019-01-08 stsp #include "got_lib_path.h"
34 718b3ab0 2018-03-17 stsp #include "got_lib_fileindex.h"
35 b25ae4fa 2019-02-04 stsp #include "got_lib_worktree.h"
37 eb983b4b 2019-03-26 stsp /* got_fileindex_entry flags */
38 eb983b4b 2019-03-26 stsp #define GOT_FILEIDX_F_PATH_LEN 0x00000fff
39 eb983b4b 2019-03-26 stsp #define GOT_FILEIDX_F_STAGE 0x00003000
40 eb983b4b 2019-03-26 stsp #define GOT_FILEIDX_F_EXTENDED 0x00004000
41 eb983b4b 2019-03-26 stsp #define GOT_FILEIDX_F_ASSUME_VALID 0x00008000
42 ddce0520 2019-03-26 stsp #define GOT_FILEIDX_F_NOT_FLUSHED 0x00010000
43 ddce0520 2019-03-26 stsp #define GOT_FILEIDX_F_NO_BLOB 0x00020000
44 ddce0520 2019-03-26 stsp #define GOT_FILEIDX_F_NO_COMMIT 0x00040000
46 133d2798 2019-01-08 stsp struct got_fileindex {
47 133d2798 2019-01-08 stsp struct got_fileindex_tree entries;
48 133d2798 2019-01-08 stsp int nentries;
49 133d2798 2019-01-08 stsp #define GOT_FILEIDX_MAX_ENTRIES INT_MAX
52 c48c4a9c 2018-03-11 stsp const struct got_error *
53 51514078 2018-12-25 stsp got_fileindex_entry_update(struct got_fileindex_entry *entry,
54 02c07007 2019-02-10 stsp const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1,
55 02c07007 2019-02-10 stsp int update_timestamps)
57 c48c4a9c 2018-03-11 stsp struct stat sb;
59 c34b20a2 2018-03-12 stsp if (lstat(ondisk_path, &sb) != 0)
60 c48c4a9c 2018-03-11 stsp return got_error_from_errno();
62 02c07007 2019-02-10 stsp if (update_timestamps) {
63 02c07007 2019-02-10 stsp entry->ctime_sec = sb.st_ctime;
64 02c07007 2019-02-10 stsp entry->ctime_nsec = sb.st_ctimensec;
65 02c07007 2019-02-10 stsp entry->mtime_sec = sb.st_mtime;
66 02c07007 2019-02-10 stsp entry->mtime_nsec = sb.st_mtimensec;
68 51514078 2018-12-25 stsp entry->uid = sb.st_uid;
69 51514078 2018-12-25 stsp entry->gid = sb.st_gid;
70 51514078 2018-12-25 stsp entry->size = (sb.st_size & 0xffffffff);
71 51514078 2018-12-25 stsp if (sb.st_mode & S_IFLNK)
72 a7f9d64d 2019-01-13 stsp entry->mode = GOT_FILEIDX_MODE_SYMLINK;
74 a7f9d64d 2019-01-13 stsp entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
75 51514078 2018-12-25 stsp entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
76 a7f9d64d 2019-01-13 stsp GOT_FILEIDX_MODE_PERMS_SHIFT);
78 ddce0520 2019-03-26 stsp if (blob_sha1) {
79 ddce0520 2019-03-26 stsp memcpy(entry->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
80 ddce0520 2019-03-26 stsp entry->flags &= ~GOT_FILEIDX_F_NO_BLOB;
82 ddce0520 2019-03-26 stsp entry->flags |= GOT_FILEIDX_F_NO_BLOB;
84 ddce0520 2019-03-26 stsp if (commit_sha1) {
85 ddce0520 2019-03-26 stsp memcpy(entry->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
86 ddce0520 2019-03-26 stsp entry->flags &= ~GOT_FILEIDX_F_NO_COMMIT;
88 ddce0520 2019-03-26 stsp entry->flags |= GOT_FILEIDX_F_NO_COMMIT;
90 51514078 2018-12-25 stsp return NULL;
93 51514078 2018-12-25 stsp const struct got_error *
94 51514078 2018-12-25 stsp got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
95 51514078 2018-12-25 stsp const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
96 51514078 2018-12-25 stsp uint8_t *commit_sha1)
100 c48c4a9c 2018-03-11 stsp *entry = calloc(1, sizeof(**entry));
101 c48c4a9c 2018-03-11 stsp if (*entry == NULL)
102 0a585a0d 2018-03-17 stsp return got_error_from_errno();
104 c34b20a2 2018-03-12 stsp (*entry)->path = strdup(relpath);
105 c48c4a9c 2018-03-11 stsp if ((*entry)->path == NULL) {
106 0a585a0d 2018-03-17 stsp const struct got_error *err = got_error_from_errno();
107 c48c4a9c 2018-03-11 stsp free(*entry);
108 c48c4a9c 2018-03-11 stsp *entry = NULL;
109 0a585a0d 2018-03-17 stsp return err;
112 c34b20a2 2018-03-12 stsp len = strlen(relpath);
113 a7f9d64d 2019-01-13 stsp if (len > GOT_FILEIDX_F_PATH_LEN)
114 a7f9d64d 2019-01-13 stsp len = GOT_FILEIDX_F_PATH_LEN;
115 c48c4a9c 2018-03-11 stsp (*entry)->flags |= len;
117 51514078 2018-12-25 stsp return got_fileindex_entry_update(*entry, ondisk_path, blob_sha1,
118 02c07007 2019-02-10 stsp commit_sha1, 1);
122 7426bbfd 2018-12-24 stsp got_fileindex_entry_free(struct got_fileindex_entry *entry)
124 c48c4a9c 2018-03-11 stsp free(entry->path);
125 c48c4a9c 2018-03-11 stsp free(entry);
128 50952927 2019-01-12 stsp static const struct got_error *
129 50952927 2019-01-12 stsp add_entry(struct got_fileindex *fileindex, struct got_fileindex_entry *entry)
131 133d2798 2019-01-08 stsp if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
132 133d2798 2019-01-08 stsp return got_error(GOT_ERR_NO_SPACE);
134 133d2798 2019-01-08 stsp RB_INSERT(got_fileindex_tree, &fileindex->entries, entry);
135 133d2798 2019-01-08 stsp fileindex->nentries++;
136 133d2798 2019-01-08 stsp return NULL;
139 50952927 2019-01-12 stsp const struct got_error *
140 50952927 2019-01-12 stsp got_fileindex_entry_add(struct got_fileindex *fileindex,
141 50952927 2019-01-12 stsp struct got_fileindex_entry *entry)
143 50952927 2019-01-12 stsp /* Flag this entry until it gets written out to disk. */
144 e288864f 2019-03-26 stsp entry->flags |= GOT_FILEIDX_F_NOT_FLUSHED;
146 50952927 2019-01-12 stsp return add_entry(fileindex, entry);
150 512f0d0e 2019-01-02 stsp got_fileindex_entry_remove(struct got_fileindex *fileindex,
151 512f0d0e 2019-01-02 stsp struct got_fileindex_entry *entry)
153 133d2798 2019-01-08 stsp RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
154 133d2798 2019-01-08 stsp fileindex->nentries--;
157 51514078 2018-12-25 stsp struct got_fileindex_entry *
158 51514078 2018-12-25 stsp got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
160 133d2798 2019-01-08 stsp struct got_fileindex_entry key;
161 133d2798 2019-01-08 stsp memset(&key, 0, sizeof(key));
162 133d2798 2019-01-08 stsp key.path = (char *)path;
163 133d2798 2019-01-08 stsp return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
166 512f0d0e 2019-01-02 stsp const struct got_error *
167 e1ed7f77 2019-01-06 stsp got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
168 b504a804 2019-01-08 stsp got_fileindex_cb cb, void *cb_arg)
170 133d2798 2019-01-08 stsp const struct got_error *err;
171 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry, *tmp;
173 133d2798 2019-01-08 stsp RB_FOREACH_SAFE(entry, got_fileindex_tree, &fileindex->entries, tmp) {
174 133d2798 2019-01-08 stsp err = (*cb)(cb_arg, entry);
176 133d2798 2019-01-08 stsp return err;
178 b504a804 2019-01-08 stsp return NULL;
181 133d2798 2019-01-08 stsp struct got_fileindex *
182 133d2798 2019-01-08 stsp got_fileindex_alloc(void)
184 133d2798 2019-01-08 stsp struct got_fileindex *fileindex;
186 133d2798 2019-01-08 stsp fileindex = calloc(1, sizeof(*fileindex));
187 133d2798 2019-01-08 stsp if (fileindex == NULL)
188 133d2798 2019-01-08 stsp return NULL;
190 133d2798 2019-01-08 stsp RB_INIT(&fileindex->entries);
191 133d2798 2019-01-08 stsp return fileindex;
195 7426bbfd 2018-12-24 stsp got_fileindex_free(struct got_fileindex *fileindex)
197 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry;
199 133d2798 2019-01-08 stsp while ((entry = RB_MIN(got_fileindex_tree, &fileindex->entries))) {
200 133d2798 2019-01-08 stsp RB_REMOVE(got_fileindex_tree, &fileindex->entries, entry);
201 133d2798 2019-01-08 stsp got_fileindex_entry_free(entry);
203 9d31a1d8 2018-03-11 stsp free(fileindex);
206 c34b20a2 2018-03-12 stsp static const struct got_error *
207 c34b20a2 2018-03-12 stsp write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
211 c34b20a2 2018-03-12 stsp val = htobe64(val);
212 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
213 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
214 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
215 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
216 c34b20a2 2018-03-12 stsp return NULL;
219 c34b20a2 2018-03-12 stsp static const struct got_error *
220 c34b20a2 2018-03-12 stsp write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
224 c34b20a2 2018-03-12 stsp val = htobe32(val);
225 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
226 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
227 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
228 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
229 c34b20a2 2018-03-12 stsp return NULL;
232 c34b20a2 2018-03-12 stsp static const struct got_error *
233 c34b20a2 2018-03-12 stsp write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
237 c34b20a2 2018-03-12 stsp val = htobe16(val);
238 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
239 3fe2daf1 2018-12-24 stsp n = fwrite(&val, 1, sizeof(val), outfile);
240 c34b20a2 2018-03-12 stsp if (n != sizeof(val))
241 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
242 c34b20a2 2018-03-12 stsp return NULL;
245 c34b20a2 2018-03-12 stsp static const struct got_error *
246 c34b20a2 2018-03-12 stsp write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile)
248 3c5b70f2 2018-12-27 stsp size_t n, len, pad = 0;
249 c34b20a2 2018-03-12 stsp static const uint8_t zero[8] = { 0 };
251 c34b20a2 2018-03-12 stsp len = strlen(path);
252 3c5b70f2 2018-12-27 stsp while ((len + pad) % 8 != 0)
254 3c5b70f2 2018-12-27 stsp if (pad == 0)
255 3c5b70f2 2018-12-27 stsp pad = 8; /* NUL-terminate */
257 c34b20a2 2018-03-12 stsp SHA1Update(ctx, path, len);
258 c34b20a2 2018-03-12 stsp n = fwrite(path, 1, len, outfile);
259 c34b20a2 2018-03-12 stsp if (n != len)
260 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
261 c34b20a2 2018-03-12 stsp SHA1Update(ctx, zero, pad);
262 c34b20a2 2018-03-12 stsp n = fwrite(zero, 1, pad, outfile);
263 c34b20a2 2018-03-12 stsp if (n != pad)
264 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
265 c34b20a2 2018-03-12 stsp return NULL;
268 c34b20a2 2018-03-12 stsp static const struct got_error *
269 c34b20a2 2018-03-12 stsp write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
270 c34b20a2 2018-03-12 stsp FILE *outfile)
272 c34b20a2 2018-03-12 stsp const struct got_error *err;
275 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->ctime_sec, outfile);
277 c34b20a2 2018-03-12 stsp return err;
278 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->ctime_nsec, outfile);
280 c34b20a2 2018-03-12 stsp return err;
281 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->mtime_sec, outfile);
283 c34b20a2 2018-03-12 stsp return err;
284 c34b20a2 2018-03-12 stsp err = write_fileindex_val64(ctx, entry->mtime_nsec, outfile);
286 c34b20a2 2018-03-12 stsp return err;
288 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->uid, outfile);
290 c34b20a2 2018-03-12 stsp return err;
291 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->gid, outfile);
293 c34b20a2 2018-03-12 stsp return err;
294 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->size, outfile);
296 c34b20a2 2018-03-12 stsp return err;
298 c34b20a2 2018-03-12 stsp err = write_fileindex_val16(ctx, entry->mode, outfile);
300 c34b20a2 2018-03-12 stsp return err;
302 c34b20a2 2018-03-12 stsp SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
303 c34b20a2 2018-03-12 stsp n = fwrite(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
304 fc76cabb 2018-12-25 stsp if (n != SHA1_DIGEST_LENGTH)
305 fc76cabb 2018-12-25 stsp return got_ferror(outfile, GOT_ERR_IO);
307 fc76cabb 2018-12-25 stsp SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
308 fc76cabb 2018-12-25 stsp n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
309 c34b20a2 2018-03-12 stsp if (n != SHA1_DIGEST_LENGTH)
310 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
312 c34b20a2 2018-03-12 stsp err = write_fileindex_val32(ctx, entry->flags, outfile);
314 c34b20a2 2018-03-12 stsp return err;
316 c34b20a2 2018-03-12 stsp err = write_fileindex_path(ctx, entry->path, outfile);
317 c34b20a2 2018-03-12 stsp return err;
320 9d31a1d8 2018-03-11 stsp const struct got_error *
321 9d31a1d8 2018-03-11 stsp got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
323 b504a804 2019-01-08 stsp const struct got_error *err = NULL;
324 c34b20a2 2018-03-12 stsp struct got_fileindex_hdr hdr;
325 c34b20a2 2018-03-12 stsp SHA1_CTX ctx;
326 c34b20a2 2018-03-12 stsp uint8_t sha1[SHA1_DIGEST_LENGTH];
328 133d2798 2019-01-08 stsp struct got_fileindex_entry *entry;
330 c34b20a2 2018-03-12 stsp SHA1Init(&ctx);
332 c34b20a2 2018-03-12 stsp hdr.signature = htobe32(GOT_FILE_INDEX_SIGNATURE);
333 c34b20a2 2018-03-12 stsp hdr.version = htobe32(GOT_FILE_INDEX_VERSION);
334 133d2798 2019-01-08 stsp hdr.nentries = htobe32(fileindex->nentries);
336 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
337 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
338 a5744d71 2019-01-12 stsp SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
339 a5744d71 2019-01-12 stsp n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile);
340 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.signature))
341 a5744d71 2019-01-12 stsp return got_ferror(outfile, GOT_ERR_IO);
342 a5744d71 2019-01-12 stsp n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile);
343 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.version))
344 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
345 a5744d71 2019-01-12 stsp n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile);
346 a5744d71 2019-01-12 stsp if (n != sizeof(hdr.nentries))
347 a5744d71 2019-01-12 stsp return got_ferror(outfile, GOT_ERR_IO);
349 133d2798 2019-01-08 stsp RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) {
350 e288864f 2019-03-26 stsp entry->flags &= ~GOT_FILEIDX_F_NOT_FLUSHED;
351 133d2798 2019-01-08 stsp err = write_fileindex_entry(&ctx, entry, outfile);
353 133d2798 2019-01-08 stsp return err;
356 c34b20a2 2018-03-12 stsp SHA1Final(sha1, &ctx);
357 c34b20a2 2018-03-12 stsp n = fwrite(sha1, 1, sizeof(sha1), outfile);
358 c34b20a2 2018-03-12 stsp if (n != sizeof(sha1))
359 c34b20a2 2018-03-12 stsp return got_ferror(outfile, GOT_ERR_IO);
361 27d0e5bd 2019-01-12 stsp if (fflush(outfile) != 0)
362 27d0e5bd 2019-01-12 stsp return got_error_from_errno();
364 52a74475 2018-12-24 stsp return NULL;
367 52a74475 2018-12-24 stsp static const struct got_error *
368 52a74475 2018-12-24 stsp read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
372 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
373 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
374 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
375 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
376 9eb6a6b2 2018-12-24 stsp *val = be64toh(*val);
377 52a74475 2018-12-24 stsp return NULL;
380 52a74475 2018-12-24 stsp static const struct got_error *
381 52a74475 2018-12-24 stsp read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
385 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
386 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
387 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
388 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
389 9eb6a6b2 2018-12-24 stsp *val = be32toh(*val);
390 52a74475 2018-12-24 stsp return NULL;
393 52a74475 2018-12-24 stsp static const struct got_error *
394 52a74475 2018-12-24 stsp read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
398 3fe2daf1 2018-12-24 stsp n = fread(val, 1, sizeof(*val), infile);
399 3fe2daf1 2018-12-24 stsp if (n != sizeof(*val))
400 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
401 3fe2daf1 2018-12-24 stsp SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
402 9eb6a6b2 2018-12-24 stsp *val = be16toh(*val);
403 52a74475 2018-12-24 stsp return NULL;
406 52a74475 2018-12-24 stsp static const struct got_error *
407 52a74475 2018-12-24 stsp read_fileindex_path(char **path, SHA1_CTX *ctx, FILE *infile)
409 52a74475 2018-12-24 stsp const struct got_error *err = NULL;
410 52a74475 2018-12-24 stsp uint8_t buf[8];
411 52a74475 2018-12-24 stsp size_t n, len = 0, totlen = sizeof(buf);
413 52a74475 2018-12-24 stsp *path = malloc(totlen);
414 52a74475 2018-12-24 stsp if (*path == NULL)
415 52a74475 2018-12-24 stsp return got_error_from_errno();
418 52a74475 2018-12-24 stsp n = fread(buf, 1, sizeof(buf), infile);
419 52a74475 2018-12-24 stsp if (n != sizeof(buf))
420 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
421 52a74475 2018-12-24 stsp if (len + sizeof(buf) > totlen) {
422 52a74475 2018-12-24 stsp char *p = reallocarray(*path, totlen + sizeof(buf), 1);
423 52a74475 2018-12-24 stsp if (p == NULL) {
424 52a74475 2018-12-24 stsp err = got_error_from_errno();
427 52a74475 2018-12-24 stsp totlen += sizeof(buf);
430 52a74475 2018-12-24 stsp SHA1Update(ctx, buf, sizeof(buf));
431 52a74475 2018-12-24 stsp memcpy(*path + len, buf, sizeof(buf));
432 52a74475 2018-12-24 stsp len += sizeof(buf);
433 60619907 2018-12-27 stsp } while (memchr(buf, '\0', sizeof(buf)) == NULL);
436 52a74475 2018-12-24 stsp free(*path);
437 52a74475 2018-12-24 stsp *path = NULL;
439 52a74475 2018-12-24 stsp return err;
442 52a74475 2018-12-24 stsp static const struct got_error *
443 52a74475 2018-12-24 stsp read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
444 52a74475 2018-12-24 stsp FILE *infile)
446 52a74475 2018-12-24 stsp const struct got_error *err;
447 52a74475 2018-12-24 stsp struct got_fileindex_entry *entry;
450 52a74475 2018-12-24 stsp *entryp = NULL;
452 52a74475 2018-12-24 stsp entry = calloc(1, sizeof(*entry));
453 52a74475 2018-12-24 stsp if (entry == NULL)
454 52a74475 2018-12-24 stsp return got_error_from_errno();
456 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->ctime_sec, ctx, infile);
459 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->ctime_nsec, ctx, infile);
462 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->mtime_sec, ctx, infile);
465 52a74475 2018-12-24 stsp err = read_fileindex_val64(&entry->mtime_nsec, ctx, infile);
469 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->uid, ctx, infile);
472 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->gid, ctx, infile);
475 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->size, ctx, infile);
479 52a74475 2018-12-24 stsp err = read_fileindex_val16(&entry->mode, ctx, infile);
483 52a74475 2018-12-24 stsp n = fread(entry->blob_sha1, 1, SHA1_DIGEST_LENGTH, infile);
484 52a74475 2018-12-24 stsp if (n != SHA1_DIGEST_LENGTH) {
485 27793341 2019-01-12 stsp err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
488 52a74475 2018-12-24 stsp SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
490 fc76cabb 2018-12-25 stsp n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
491 fc76cabb 2018-12-25 stsp if (n != SHA1_DIGEST_LENGTH) {
492 27793341 2019-01-12 stsp err = got_ferror(infile, GOT_ERR_FILEIDX_BAD);
495 fc76cabb 2018-12-25 stsp SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
497 52a74475 2018-12-24 stsp err = read_fileindex_val32(&entry->flags, ctx, infile);
501 52a74475 2018-12-24 stsp err = read_fileindex_path(&entry->path, ctx, infile);
504 52a74475 2018-12-24 stsp free(entry);
506 52a74475 2018-12-24 stsp *entryp = entry;
507 52a74475 2018-12-24 stsp return err;
510 52a74475 2018-12-24 stsp const struct got_error *
511 52a74475 2018-12-24 stsp got_fileindex_read(struct got_fileindex *fileindex, FILE *infile)
513 52a74475 2018-12-24 stsp const struct got_error *err = NULL;
514 52a74475 2018-12-24 stsp struct got_fileindex_hdr hdr;
515 52a74475 2018-12-24 stsp SHA1_CTX ctx;
516 52a74475 2018-12-24 stsp struct got_fileindex_entry *entry;
517 52a74475 2018-12-24 stsp uint8_t sha1_expected[SHA1_DIGEST_LENGTH];
518 52a74475 2018-12-24 stsp uint8_t sha1[SHA1_DIGEST_LENGTH];
522 52a74475 2018-12-24 stsp SHA1Init(&ctx);
524 b6d05318 2019-01-13 stsp n = fread(&hdr.signature, 1, sizeof(hdr.signature), infile);
525 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.signature)) {
526 b6d05318 2019-01-13 stsp if (n == 0) /* EOF */
527 b6d05318 2019-01-13 stsp return NULL;
528 b6d05318 2019-01-13 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
530 b6d05318 2019-01-13 stsp n = fread(&hdr.version, 1, sizeof(hdr.version), infile);
531 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.version)) {
532 51514078 2018-12-25 stsp if (n == 0) /* EOF */
533 51514078 2018-12-25 stsp return NULL;
534 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
536 b6d05318 2019-01-13 stsp n = fread(&hdr.nentries, 1, sizeof(hdr.nentries), infile);
537 b6d05318 2019-01-13 stsp if (n != sizeof(hdr.nentries)) {
538 b6d05318 2019-01-13 stsp if (n == 0) /* EOF */
539 b6d05318 2019-01-13 stsp return NULL;
540 b6d05318 2019-01-13 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
543 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature));
544 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version));
545 b6d05318 2019-01-13 stsp SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries));
547 9eb6a6b2 2018-12-24 stsp hdr.signature = be32toh(hdr.signature);
548 9eb6a6b2 2018-12-24 stsp hdr.version = be32toh(hdr.version);
549 9eb6a6b2 2018-12-24 stsp hdr.nentries = be32toh(hdr.nentries);
551 52a74475 2018-12-24 stsp if (hdr.signature != GOT_FILE_INDEX_SIGNATURE)
552 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_SIG);
553 52a74475 2018-12-24 stsp if (hdr.version != GOT_FILE_INDEX_VERSION)
554 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_VER);
556 52a74475 2018-12-24 stsp for (i = 0; i < hdr.nentries; i++) {
557 52a74475 2018-12-24 stsp err = read_fileindex_entry(&entry, &ctx, infile);
559 52a74475 2018-12-24 stsp return err;
560 50952927 2019-01-12 stsp err = add_entry(fileindex, entry);
562 52a74475 2018-12-24 stsp return err;
565 52a74475 2018-12-24 stsp n = fread(sha1_expected, 1, sizeof(sha1_expected), infile);
566 52a74475 2018-12-24 stsp if (n != sizeof(sha1_expected))
567 27793341 2019-01-12 stsp return got_ferror(infile, GOT_ERR_FILEIDX_BAD);
568 52a74475 2018-12-24 stsp SHA1Final(sha1, &ctx);
569 52a74475 2018-12-24 stsp if (memcmp(sha1, sha1_expected, SHA1_DIGEST_LENGTH) != 0)
570 52a74475 2018-12-24 stsp return got_error(GOT_ERR_FILEIDX_CSUM);
572 9d31a1d8 2018-03-11 stsp return NULL;
575 c2ac9456 2019-03-15 stsp static struct got_fileindex_entry *
576 50952927 2019-01-12 stsp walk_fileindex(struct got_fileindex *fileindex, struct got_fileindex_entry *ie)
578 50952927 2019-01-12 stsp struct got_fileindex_entry *next;
580 50952927 2019-01-12 stsp next = RB_NEXT(got_fileindex_tree, &fileindex->entries, ie);
582 50952927 2019-01-12 stsp /* Skip entries which were newly added by diff callbacks. */
583 e288864f 2019-03-26 stsp while (next && (next->flags & GOT_FILEIDX_F_NOT_FLUSHED))
584 50952927 2019-01-12 stsp next = RB_NEXT(got_fileindex_tree, &fileindex->entries, next);
586 50952927 2019-01-12 stsp return next;
589 8da9e5f4 2019-01-12 stsp static const struct got_error *
590 9d2a8e53 2019-01-28 stsp diff_fileindex_tree(struct got_fileindex *, struct got_fileindex_entry **,
591 9d2a8e53 2019-01-28 stsp struct got_tree_object *, const char *, struct got_repository *,
592 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *, void *);
594 9d2a8e53 2019-01-28 stsp static const struct got_error *
595 8da9e5f4 2019-01-12 stsp walk_tree(struct got_tree_entry **next, struct got_fileindex *fileindex,
596 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry **ie, struct got_tree_entry *te,
597 8da9e5f4 2019-01-12 stsp const char *path, struct got_repository *repo,
598 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
600 8da9e5f4 2019-01-12 stsp const struct got_error *err = NULL;
602 bd4792ec 2019-01-13 stsp if (S_ISDIR(te->mode)) {
603 8da9e5f4 2019-01-12 stsp char *subpath;
604 8da9e5f4 2019-01-12 stsp struct got_tree_object *subtree;
606 8da9e5f4 2019-01-12 stsp if (asprintf(&subpath, "%s%s%s", path,
607 8da9e5f4 2019-01-12 stsp path[0] == '\0' ? "" : "/", te->name) == -1)
608 8da9e5f4 2019-01-12 stsp return got_error_from_errno();
610 8da9e5f4 2019-01-12 stsp err = got_object_open_as_tree(&subtree, repo, te->id);
612 8da9e5f4 2019-01-12 stsp free(subpath);
613 8da9e5f4 2019-01-12 stsp return err;
616 8da9e5f4 2019-01-12 stsp err = diff_fileindex_tree(fileindex, ie, subtree,
617 8da9e5f4 2019-01-12 stsp subpath, repo, cb, cb_arg);
618 8da9e5f4 2019-01-12 stsp free(subpath);
619 8da9e5f4 2019-01-12 stsp got_object_tree_close(subtree);
621 8da9e5f4 2019-01-12 stsp return err;
624 bd4792ec 2019-01-13 stsp *next = SIMPLEQ_NEXT(te, entry);
625 8da9e5f4 2019-01-12 stsp return NULL;
628 8da9e5f4 2019-01-12 stsp static const struct got_error *
629 8da9e5f4 2019-01-12 stsp diff_fileindex_tree(struct got_fileindex *fileindex,
630 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry **ie, struct got_tree_object *tree,
631 8da9e5f4 2019-01-12 stsp const char *path, struct got_repository *repo,
632 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
634 8da9e5f4 2019-01-12 stsp const struct got_error *err = NULL;
635 8da9e5f4 2019-01-12 stsp struct got_tree_entry *te = NULL;
636 8da9e5f4 2019-01-12 stsp size_t path_len = strlen(path);
637 8da9e5f4 2019-01-12 stsp const struct got_tree_entries *entries;
638 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry *next;
640 8da9e5f4 2019-01-12 stsp entries = got_object_tree_get_entries(tree);
641 8da9e5f4 2019-01-12 stsp te = SIMPLEQ_FIRST(&entries->head);
642 500cd40f 2019-02-04 stsp while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || te) {
643 8da9e5f4 2019-01-12 stsp if (te && *ie) {
644 18831e78 2019-02-10 stsp char *te_path;
646 18831e78 2019-02-10 stsp if (asprintf(&te_path, "%s/%s", path, te->name) == -1) {
647 18831e78 2019-02-10 stsp err = got_error_from_errno();
650 18831e78 2019-02-10 stsp cmp = got_path_cmp((*ie)->path, te_path);
651 18831e78 2019-02-10 stsp free(te_path);
652 8da9e5f4 2019-01-12 stsp if (cmp == 0) {
653 8da9e5f4 2019-01-12 stsp err = cb->diff_old_new(cb_arg, *ie, te,
657 50952927 2019-01-12 stsp *ie = walk_fileindex(fileindex, *ie);
658 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te,
659 8da9e5f4 2019-01-12 stsp path, repo, cb, cb_arg);
660 50952927 2019-01-12 stsp } else if (cmp < 0 ) {
661 50952927 2019-01-12 stsp next = walk_fileindex(fileindex, *ie);
662 8da9e5f4 2019-01-12 stsp err = cb->diff_old(cb_arg, *ie, path);
665 8da9e5f4 2019-01-12 stsp *ie = next;
667 8da9e5f4 2019-01-12 stsp err = cb->diff_new(cb_arg, te, path);
670 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te,
671 8da9e5f4 2019-01-12 stsp path, repo, cb, cb_arg);
675 8da9e5f4 2019-01-12 stsp } else if (*ie) {
676 50952927 2019-01-12 stsp next = walk_fileindex(fileindex, *ie);
677 8da9e5f4 2019-01-12 stsp err = cb->diff_old(cb_arg, *ie, path);
680 8da9e5f4 2019-01-12 stsp *ie = next;
681 8da9e5f4 2019-01-12 stsp } else if (te) {
682 8da9e5f4 2019-01-12 stsp err = cb->diff_new(cb_arg, te, path);
685 8da9e5f4 2019-01-12 stsp err = walk_tree(&te, fileindex, ie, te, path, repo, cb,
692 8da9e5f4 2019-01-12 stsp return err;
695 8da9e5f4 2019-01-12 stsp const struct got_error *
696 8da9e5f4 2019-01-12 stsp got_fileindex_diff_tree(struct got_fileindex *fileindex,
697 8da9e5f4 2019-01-12 stsp struct got_tree_object *tree, struct got_repository *repo,
698 f44ffd20 2019-02-04 stsp struct got_fileindex_diff_tree_cb *cb, void *cb_arg)
700 8da9e5f4 2019-01-12 stsp struct got_fileindex_entry *min;
701 8da9e5f4 2019-01-12 stsp min = RB_MIN(got_fileindex_tree, &fileindex->entries);
702 8da9e5f4 2019-01-12 stsp return diff_fileindex_tree(fileindex, &min, tree, "", repo, cb, cb_arg);
705 d1f6d47b 2019-02-04 stsp static const struct got_error *
706 d1f6d47b 2019-02-04 stsp diff_fileindex_dir(struct got_fileindex *, struct got_fileindex_entry **, DIR *,
707 c7f4312f 2019-02-05 stsp const char *, const char *, struct got_repository *,
708 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *, void *);
710 d1f6d47b 2019-02-04 stsp static const struct got_error *
711 f5d3d7af 2019-02-05 stsp walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
712 f5d3d7af 2019-02-05 stsp struct got_fileindex_entry **ie, struct got_pathlist_entry *dle,
713 c7f4312f 2019-02-05 stsp const char *path, DIR *dir, const char *rootpath,
714 c7f4312f 2019-02-05 stsp struct got_repository *repo, struct got_fileindex_diff_dir_cb *cb,
715 c7f4312f 2019-02-05 stsp void *cb_arg)
717 d1f6d47b 2019-02-04 stsp const struct got_error *err = NULL;
718 f5d3d7af 2019-02-05 stsp struct dirent *de = dle->data;
720 f5d3d7af 2019-02-05 stsp if (de->d_type == DT_DIR) {
721 d1f6d47b 2019-02-04 stsp char *subpath;
722 c7f4312f 2019-02-05 stsp char *subdirpath;
723 d1f6d47b 2019-02-04 stsp DIR *subdir;
725 d1f6d47b 2019-02-04 stsp if (asprintf(&subpath, "%s%s%s", path,
726 f5d3d7af 2019-02-05 stsp path[0] == '\0' ? "" : "/", de->d_name) == -1)
727 d1f6d47b 2019-02-04 stsp return got_error_from_errno();
729 c7f4312f 2019-02-05 stsp if (asprintf(&subdirpath, "%s/%s", rootpath, subpath) == -1) {
730 c7f4312f 2019-02-05 stsp free(subpath);
731 c7f4312f 2019-02-05 stsp return got_error_from_errno();
734 c7f4312f 2019-02-05 stsp subdir = opendir(subdirpath);
735 d1f6d47b 2019-02-04 stsp if (subdir == NULL) {
736 d1f6d47b 2019-02-04 stsp free(subpath);
737 c7f4312f 2019-02-05 stsp free(subdirpath);
738 d1f6d47b 2019-02-04 stsp return got_error_from_errno();
741 c7f4312f 2019-02-05 stsp err = diff_fileindex_dir(fileindex, ie, subdir, rootpath,
742 c7f4312f 2019-02-05 stsp subpath, repo, cb, cb_arg);
743 d1f6d47b 2019-02-04 stsp free(subpath);
744 c7f4312f 2019-02-05 stsp free(subdirpath);
745 d1f6d47b 2019-02-04 stsp closedir(subdir);
747 d1f6d47b 2019-02-04 stsp return err;
750 f5d3d7af 2019-02-05 stsp *next = TAILQ_NEXT(dle, entry);
751 d1f6d47b 2019-02-04 stsp return NULL;
754 d1f6d47b 2019-02-04 stsp static const struct got_error *
755 d1f6d47b 2019-02-04 stsp diff_fileindex_dir(struct got_fileindex *fileindex,
756 c7f4312f 2019-02-05 stsp struct got_fileindex_entry **ie, DIR *dir, const char *rootpath,
757 c7f4312f 2019-02-05 stsp const char *path, struct got_repository *repo,
758 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
760 d1f6d47b 2019-02-04 stsp const struct got_error *err = NULL;
761 d1f6d47b 2019-02-04 stsp struct dirent *de = NULL;
762 d1f6d47b 2019-02-04 stsp size_t path_len = strlen(path);
763 d1f6d47b 2019-02-04 stsp struct got_fileindex_entry *next;
764 f5d3d7af 2019-02-05 stsp struct got_pathlist_head dirlist;
765 f5d3d7af 2019-02-05 stsp struct got_pathlist_entry *dle;
767 f5d3d7af 2019-02-05 stsp TAILQ_INIT(&dirlist);
769 500cd40f 2019-02-04 stsp while (1) {
770 f5d3d7af 2019-02-05 stsp struct got_pathlist_entry *new = NULL;
771 ed83bff7 2019-02-05 stsp struct dirent *dep = NULL;
773 ed83bff7 2019-02-05 stsp de = malloc(sizeof(struct dirent) + NAME_MAX + 1);
774 ed83bff7 2019-02-05 stsp if (de == NULL) {
775 ed83bff7 2019-02-05 stsp err = got_error_from_errno();
779 ed83bff7 2019-02-05 stsp if (readdir_r(dir, de, &dep) != 0) {
780 ed83bff7 2019-02-05 stsp err = got_error_from_errno();
784 ed83bff7 2019-02-05 stsp if (dep == NULL) {
789 b1ec3986 2019-02-04 stsp if (strcmp(de->d_name, ".") == 0 ||
790 b25ae4fa 2019-02-04 stsp strcmp(de->d_name, "..") == 0 ||
791 b25ae4fa 2019-02-04 stsp (path[0] == '\0' &&
792 ed83bff7 2019-02-05 stsp strcmp(de->d_name, GOT_WORKTREE_GOT_DIR) == 0)) {
797 f5d3d7af 2019-02-05 stsp err = got_pathlist_insert(&new, &dirlist, de->d_name, de);
800 f5d3d7af 2019-02-05 stsp if (new == NULL) {
801 f5d3d7af 2019-02-05 stsp err = got_error(GOT_ERR_DIR_DUP_ENTRY);
806 f5d3d7af 2019-02-05 stsp dle = TAILQ_FIRST(&dirlist);
807 500cd40f 2019-02-04 stsp while ((*ie && got_path_is_child((*ie)->path, path, path_len)) || dle) {
808 500cd40f 2019-02-04 stsp if (dle && *ie) {
809 18831e78 2019-02-10 stsp char *de_path;
811 f5d3d7af 2019-02-05 stsp de = dle->data;
812 18831e78 2019-02-10 stsp if (asprintf(&de_path, "%s/%s", path,
813 18831e78 2019-02-10 stsp de->d_name) == -1) {
814 18831e78 2019-02-10 stsp err = got_error_from_errno();
817 18831e78 2019-02-10 stsp cmp = got_path_cmp((*ie)->path, de_path);
818 18831e78 2019-02-10 stsp free(de_path);
819 d1f6d47b 2019-02-04 stsp if (cmp == 0) {
820 f5d3d7af 2019-02-05 stsp err = cb->diff_old_new(cb_arg, *ie, de, path);
823 d1f6d47b 2019-02-04 stsp *ie = walk_fileindex(fileindex, *ie);
824 500cd40f 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path,
825 c7f4312f 2019-02-05 stsp dir, rootpath, repo, cb, cb_arg);
826 d1f6d47b 2019-02-04 stsp } else if (cmp < 0 ) {
827 d1f6d47b 2019-02-04 stsp next = walk_fileindex(fileindex, *ie);
828 d1f6d47b 2019-02-04 stsp err = cb->diff_old(cb_arg, *ie, path);
831 d1f6d47b 2019-02-04 stsp *ie = next;
833 f5d3d7af 2019-02-05 stsp err = cb->diff_new(cb_arg, de, path);
836 500cd40f 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path,
837 c7f4312f 2019-02-05 stsp dir, rootpath, repo, cb, cb_arg);
841 554b91b1 2019-02-04 stsp } else if (*ie) {
842 554b91b1 2019-02-04 stsp next = walk_fileindex(fileindex, *ie);
843 554b91b1 2019-02-04 stsp err = cb->diff_old(cb_arg, *ie, path);
846 554b91b1 2019-02-04 stsp *ie = next;
847 554b91b1 2019-02-04 stsp } else if (dle) {
848 763e1377 2019-02-05 stsp de = dle->data;
849 f5d3d7af 2019-02-05 stsp err = cb->diff_new(cb_arg, de, path);
852 554b91b1 2019-02-04 stsp err = walk_dir(&dle, fileindex, ie, dle, path, dir,
853 c7f4312f 2019-02-05 stsp rootpath, repo, cb, cb_arg);
859 ed83bff7 2019-02-05 stsp TAILQ_FOREACH(dle, &dirlist, entry)
860 ed83bff7 2019-02-05 stsp free(dle->data);
861 f5d3d7af 2019-02-05 stsp got_pathlist_free(&dirlist);
862 d1f6d47b 2019-02-04 stsp return err;
865 d1f6d47b 2019-02-04 stsp const struct got_error *
866 c7f4312f 2019-02-05 stsp got_fileindex_diff_dir(struct got_fileindex *fileindex, DIR *rootdir,
867 927df6b7 2019-02-10 stsp const char *rootpath, const char *path, struct got_repository *repo,
868 c7f4312f 2019-02-05 stsp struct got_fileindex_diff_dir_cb *cb, void *cb_arg)
870 d1f6d47b 2019-02-04 stsp struct got_fileindex_entry *min;
871 d1f6d47b 2019-02-04 stsp min = RB_MIN(got_fileindex_tree, &fileindex->entries);
872 927df6b7 2019-02-10 stsp return diff_fileindex_dir(fileindex, &min, rootdir, rootpath, path,
873 c7f4312f 2019-02-05 stsp repo, cb, cb_arg);
876 7a9df742 2019-01-08 stsp RB_GENERATE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);