]>
Commit | Line | Data |
---|---|---|
c0e6c23d DB |
1 | /* |
2 | * Licensed under a two-clause BSD-style license. | |
3 | * See LICENSE for details. | |
4 | */ | |
5 | ||
6 | #include "git-compat-util.h" | |
723b7a27 | 7 | #include "strbuf.h" |
c0e6c23d | 8 | #include "repo_tree.h" |
c0e6c23d DB |
9 | #include "fast_export.h" |
10 | ||
c19d653c | 11 | const char *repo_read_path(const char *path, uint32_t *mode_out) |
c0e6c23d | 12 | { |
723b7a27 | 13 | int err; |
723b7a27 | 14 | static struct strbuf buf = STRBUF_INIT; |
c0e6c23d | 15 | |
723b7a27 | 16 | strbuf_reset(&buf); |
c19d653c | 17 | err = fast_export_ls(path, mode_out, &buf); |
723b7a27 JN |
18 | if (err) { |
19 | if (errno != ENOENT) | |
20 | die_errno("BUG: unexpected fast_export_ls error"); | |
43155cfe DB |
21 | /* Treat missing paths as directories. */ |
22 | *mode_out = REPO_MODE_DIR; | |
c0e6c23d | 23 | return NULL; |
c0e6c23d | 24 | } |
723b7a27 | 25 | return buf.buf; |
4f5de755 JN |
26 | } |
27 | ||
03087971 | 28 | void repo_copy(uint32_t revision, const char *src, const char *dst) |
c0e6c23d | 29 | { |
723b7a27 JN |
30 | int err; |
31 | uint32_t mode; | |
32 | static struct strbuf data = STRBUF_INIT; | |
33 | ||
34 | strbuf_reset(&data); | |
03087971 | 35 | err = fast_export_ls_rev(revision, src, &mode, &data); |
723b7a27 JN |
36 | if (err) { |
37 | if (errno != ENOENT) | |
38 | die_errno("BUG: unexpected fast_export_ls_rev error"); | |
03087971 | 39 | fast_export_delete(dst); |
723b7a27 | 40 | return; |
c0e6c23d | 41 | } |
03087971 | 42 | fast_export_modify(dst, mode, data.buf); |
c0e6c23d DB |
43 | } |
44 | ||
03087971 | 45 | void repo_delete(const char *path) |
c0e6c23d | 46 | { |
03087971 | 47 | fast_export_delete(path); |
c0e6c23d | 48 | } |