summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-10 13:16:23 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-10 13:52:56 -0300
commit8c2d19f908ba213f50f062f9e4d5ead0ead2fc1c (patch)
tree92912b37226d0b314240d478be2256965645b686
parent6a80cab5fd03d70272f7b620b36a9be096896546 (diff)
downloadeeshow-8c2d19f908ba213f50f062f9e4d5ead0ead2fc1c.tar.gz
eeshow-8c2d19f908ba213f50f062f9e4d5ead0ead2fc1c.tar.bz2
eeshow-8c2d19f908ba213f50f062f9e4d5ead0ead2fc1c.zip
eeshow/file.c, git-file.c: give access to object IDs, for caching
-rw-r--r--file.c18
-rw-r--r--file.h3
-rw-r--r--git-file.c36
-rw-r--r--git-file.h3
4 files changed, 58 insertions, 2 deletions
diff --git a/file.c b/file.c
index d2718c6..6910899 100644
--- a/file.c
+++ b/file.c
@@ -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);
diff --git a/file.h b/file.h
index 10d012d..4d5f886 100644
--- a/file.h
+++ b/file.h
@@ -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);
diff --git a/git-file.c b/git-file.c
index 26ff1c6..78d4a9b 100644
--- a/git-file.c
+++ b/git-file.c
@@ -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;
diff --git a/git-file.h b/git-file.h
index 7faba3a..973aedb 100644
--- a/git-file.h
+++ b/git-file.h
@@ -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,