1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 01:14:04 +02:00

eeshow/file.c, git-file.c: give access to object IDs, for caching

This commit is contained in:
Werner Almesberger 2016-08-10 13:16:23 -03:00
parent 54922dc343
commit 3d794c5965
4 changed files with 58 additions and 2 deletions

View File

@ -22,6 +22,24 @@
#include "file.h"
void *file_oid(const struct file *file)
{
if (!file->vcs)
return NULL;
return vcs_git_get_oid(file->vcs);
}
bool file_oid_eq(const void *a, const void *b)
{
/*
* If both a and b are NULL, we don't have revision data and thus
* can't tell if they're identical.
*/
return a && b && vcs_git_oid_eq(a, b);
}
bool file_cat(const struct file *file, void *user, const char *line)
{
printf("%s\n", line);

View File

@ -26,6 +26,9 @@ struct file {
};
void *file_oid(const struct file *file);
bool file_oid_eq(const void *a, const void *b);
bool file_cat(const struct file *file, void *user, const char *line);
char *file_graft_relative(const char *base, const char *name);

View File

@ -34,12 +34,36 @@ struct vcs_git {
git_repository *repo;
git_tree *tree;
git_object *obj;
const void *data;
unsigned size;
};
/* ----- OID matching ------------------------------------------------------ */
void *vcs_git_get_oid(const void *ctx)
{
const struct vcs_git *vcs_git = ctx;
struct git_oid *new;
new = alloc_type(git_oid);
git_oid_cpy(new, git_object_id(vcs_git->obj));
return new;
}
bool vcs_git_oid_eq(const void *a, const void *b)
{
return !git_oid_cmp(a, b);
}
/* ----- Open -------------------------------------------------------------- */
static git_repository *select_repo(const char *path)
{
git_repository *repo = NULL;
@ -298,9 +322,10 @@ static git_tree_entry *find_file(git_repository *repo, git_tree *tree,
}
static const void *get_data(git_repository *repo, git_tree_entry *entry,
static const void *get_data(struct vcs_git *vcs_git, git_tree_entry *entry,
unsigned *size)
{
git_repository *repo =vcs_git->repo;
git_object *obj;
git_blob *blob;
@ -314,6 +339,7 @@ static const void *get_data(git_repository *repo, git_tree_entry *entry,
fprintf(stderr, "%s\n", e->message);
exit(1);
}
vcs_git->obj = obj;
if (verbose > 2) {
git_buf buf = { 0 };
@ -358,7 +384,7 @@ static bool access_file_data(struct vcs_git *vcs_git, const char *name)
if (verbose)
fprintf(stderr, "reading %s\n", name);
vcs_git->data = get_data(vcs_git->repo, entry, &vcs_git->size);
vcs_git->data = get_data(vcs_git, entry, &vcs_git->size);
return 1;
}
@ -467,6 +493,9 @@ fail:
}
/* ----- Read -------------------------------------------------------------- */
bool vcs_git_read(void *ctx, struct file *file,
bool (*parse)(const struct file *file, void *user, const char *line),
void *user)
@ -489,6 +518,9 @@ bool vcs_git_read(void *ctx, struct file *file,
}
/* ----- Close ------------------------------------------------------------- */
void vcs_git_close(void *ctx)
{
struct vcs_git *vcs_git = ctx;

View File

@ -32,6 +32,9 @@ struct file;
void vcs_git_init(void);
void *vcs_git_get_oid(const void *ctx); /* mallocs */
bool vcs_git_oid_eq(const void *a, const void *b);
struct vcs_git *vcs_git_open(const char *revision, const char *name,
const struct vcs_git *related);
bool vcs_git_read(void *ctx, struct file *file,