mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-17 23:30:19 +02:00
eeshow/file.c, git-file.c: give access to object IDs, for caching
This commit is contained in:
parent
54922dc343
commit
3d794c5965
@ -22,6 +22,24 @@
|
|||||||
#include "file.h"
|
#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)
|
bool file_cat(const struct file *file, void *user, const char *line)
|
||||||
{
|
{
|
||||||
printf("%s\n", line);
|
printf("%s\n", line);
|
||||||
|
@ -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);
|
bool file_cat(const struct file *file, void *user, const char *line);
|
||||||
|
|
||||||
char *file_graft_relative(const char *base, const char *name);
|
char *file_graft_relative(const char *base, const char *name);
|
||||||
|
@ -34,12 +34,36 @@ struct vcs_git {
|
|||||||
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
|
git_object *obj;
|
||||||
|
|
||||||
const void *data;
|
const void *data;
|
||||||
unsigned size;
|
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)
|
static git_repository *select_repo(const char *path)
|
||||||
{
|
{
|
||||||
git_repository *repo = NULL;
|
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)
|
unsigned *size)
|
||||||
{
|
{
|
||||||
|
git_repository *repo =vcs_git->repo;
|
||||||
git_object *obj;
|
git_object *obj;
|
||||||
git_blob *blob;
|
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);
|
fprintf(stderr, "%s\n", e->message);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
vcs_git->obj = obj;
|
||||||
|
|
||||||
if (verbose > 2) {
|
if (verbose > 2) {
|
||||||
git_buf buf = { 0 };
|
git_buf buf = { 0 };
|
||||||
@ -358,7 +384,7 @@ static bool access_file_data(struct vcs_git *vcs_git, const char *name)
|
|||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "reading %s\n", name);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,6 +493,9 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Read -------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
bool vcs_git_read(void *ctx, struct file *file,
|
bool vcs_git_read(void *ctx, struct file *file,
|
||||||
bool (*parse)(const struct file *file, void *user, const char *line),
|
bool (*parse)(const struct file *file, void *user, const char *line),
|
||||||
void *user)
|
void *user)
|
||||||
@ -489,6 +518,9 @@ bool vcs_git_read(void *ctx, struct file *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Close ------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
void vcs_git_close(void *ctx)
|
void vcs_git_close(void *ctx)
|
||||||
{
|
{
|
||||||
struct vcs_git *vcs_git = ctx;
|
struct vcs_git *vcs_git = ctx;
|
||||||
|
@ -32,6 +32,9 @@ struct file;
|
|||||||
|
|
||||||
void vcs_git_init(void);
|
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,
|
struct vcs_git *vcs_git_open(const char *revision, const char *name,
|
||||||
const struct vcs_git *related);
|
const struct vcs_git *related);
|
||||||
bool vcs_git_read(void *ctx, struct file *file,
|
bool vcs_git_read(void *ctx, struct file *file,
|
||||||
|
Loading…
Reference in New Issue
Block a user