vcs-svn / repo_tree.con commit vcs-svn: drop string_pool (28c5d9e)
   1/*
   2 * Licensed under a two-clause BSD-style license.
   3 * See LICENSE for details.
   4 */
   5
   6#include "git-compat-util.h"
   7#include "strbuf.h"
   8#include "repo_tree.h"
   9#include "fast_export.h"
  10
  11const char *repo_read_path(const char *path)
  12{
  13        int err;
  14        uint32_t dummy;
  15        static struct strbuf buf = STRBUF_INIT;
  16
  17        strbuf_reset(&buf);
  18        err = fast_export_ls(path, &dummy, &buf);
  19        if (err) {
  20                if (errno != ENOENT)
  21                        die_errno("BUG: unexpected fast_export_ls error");
  22                return NULL;
  23        }
  24        return buf.buf;
  25}
  26
  27uint32_t repo_read_mode(const char *path)
  28{
  29        int err;
  30        uint32_t result;
  31        static struct strbuf dummy = STRBUF_INIT;
  32
  33        strbuf_reset(&dummy);
  34        err = fast_export_ls(path, &result, &dummy);
  35        if (err) {
  36                if (errno != ENOENT)
  37                        die_errno("BUG: unexpected fast_export_ls error");
  38                /* Treat missing paths as directories. */
  39                return REPO_MODE_DIR;
  40        }
  41        return result;
  42}
  43
  44void repo_copy(uint32_t revision, const char *src, const char *dst)
  45{
  46        int err;
  47        uint32_t mode;
  48        static struct strbuf data = STRBUF_INIT;
  49
  50        strbuf_reset(&data);
  51        err = fast_export_ls_rev(revision, src, &mode, &data);
  52        if (err) {
  53                if (errno != ENOENT)
  54                        die_errno("BUG: unexpected fast_export_ls_rev error");
  55                fast_export_delete(dst);
  56                return;
  57        }
  58        fast_export_modify(dst, mode, data.buf);
  59}
  60
  61void repo_delete(const char *path)
  62{
  63        fast_export_delete(path);
  64}