baseline

yet another open-source distributed versioning control system
Log | Files | Refs

commit fc8fa6eaed914e7b6af7fa9f9af48a2087142a32
parent 058694f8c9d5f6c9dc83956faad195fda3e9d44f
Author: Mohamed Aslan <maslan@sce.carleton.ca>
Date:   Sun, 25 May 2014 14:19:02 -0400

commands should now use sessions, some code refactoring and bug fixes

Diffstat:
MMakefile | 2+-
Mcmd-add.c | 90+++++++++++++++++++++++++++----------------------------------------------------
Mcmd-checkout.c | 3++-
Mcmd-commit.c | 3++-
Mcmd-init.c | 64+++++++++++++++++++---------------------------------------------
Mcommon.c | 18++++++++++++++++--
Mcommon.h | 1+
Mdircache-simple.c | 46+++++++++++++++++++++++++++++++++-------------
Mdircache.h | 5++++-
Mobjdb-fs.c | 50+++++++++++++++++++++-----------------------------
Mobjdb.h | 2+-
Asession.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asession.h | 43+++++++++++++++++++++++++++++++++++++++++++
13 files changed, 237 insertions(+), 153 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ PROG= baseline BINDIR= /usr/bin -SRCS= baseline.c config.c common.c +SRCS= baseline.c config.c common.c session.c SRCS+= cmd-add.c cmd-branch.c cmd-checkout.c cmd-commit.c cmd-help.c cmd-init.c cmd-log.c cmd-version.c SRCS+= objdb-fs.c SRCS+= dircache-simple.c diff --git a/cmd-add.c b/cmd-add.c @@ -14,74 +14,23 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> -#include <sys/stat.h> +#include <sys/stat.h> /* stat(2) */ #include <stdio.h> -#include <stdlib.h> /* EXIT_FAILURE */ -#include <string.h> /* strstr(3) */ -#include <limits.h> /* PATH_MAX */ -#include <unistd.h> /* getcwd(3) */ +#include <stdlib.h> /* EXIT_FAILURE */ +#include <string.h> /* strstr(3) */ +#include <limits.h> /* PATH_MAX */ +#include <err.h> /* errx(3) */ -#include "objdb.h" -#include "dircache.h" +#include "session.h" #include "cmd.h" -extern int objdb_baseline_get_ops(struct objdb_ops **); -extern int dircache_simple_get_ops(struct dircache_ops **); -static int is_subdir_of(const char *, const char *); - -int -cmd_add(int argc, char **argv) -{ - char cwd[PATH_MAX]; - char *path = argv[1]; - struct stat s; - struct dircache_ops *dircache; - struct dircache_ctx *dc_ctx; - struct objdb_ops *objdb; - struct objdb_ctx *db_ctx; - objdb_baseline_get_ops(&objdb); - dircache_simple_get_ops(&dircache); - if (path == NULL) { - fprintf(stderr, "baseline: error, no path specified.\n"); - return EXIT_FAILURE; - } - if (objdb->open != NULL) - objdb->open(&db_ctx, "db", ".baseline"); - if (objdb->init != NULL) /* TO BE REMOVED */ - objdb->init(db_ctx); - if (getcwd(cwd, PATH_MAX) == NULL) { - fprintf(stderr, "baseline: error, failed to get the current working directory.\n"); - return EXIT_FAILURE; - } - if (!is_subdir_of(path, cwd)) { - fprintf(stderr, "baseline: error, can not add files from outside the repository.\n"); - return EXIT_FAILURE; - } - if (stat(path, &s) == -1) { - fprintf(stderr, "baseline: error, \'%s\' does not exist.\n", path); - return EXIT_FAILURE; - } - if (dircache->init(&dc_ctx, db_ctx, objdb) == EXIT_FAILURE) { - return EXIT_FAILURE; - } - if (dircache->insert(dc_ctx, path) == EXIT_FAILURE) { - fprintf(stderr, "baseline: error, failed to add \'%s\'.\n", path); - return EXIT_FAILURE; - } - if (objdb->close != NULL) - if (objdb->close(db_ctx) == EXIT_FAILURE) - return EXIT_FAILURE; - return EXIT_SUCCESS; -} - /* * checks if first is subdir of second */ -int +static int is_subdir_of(const char *first, const char *second) { - char first_abspath[PATH_MAX]; + char first_abspath[PATH_MAX+1]; if (first == NULL || second == NULL) return 0; if (realpath(first, first_abspath) == NULL) @@ -94,3 +43,26 @@ is_subdir_of(const char *first, const char *second) return 0; } +int +cmd_add(int argc, char **argv) +{ + char *path; + struct session s; + struct stat st; + + baseline_session_begin(&s, 0); + + path = argv[1]; + if (path == NULL) + errx(EXIT_FAILURE, "error, no path specified."); + if (!is_subdir_of(path, s.repo_rootdir)) + errx(EXIT_FAILURE, "error, can not add files from outside the repository."); + if (stat(path, &st) == -1) + errx(EXIT_FAILURE, "error, \'%s\' does not exist.", path); + if (s.dc_ops->insert(s.dc_ctx, path) == EXIT_FAILURE) + errx(EXIT_FAILURE, "failed to add \'%s\'.", path); + + baseline_session_end(&s); + return EXIT_SUCCESS; +} + diff --git a/cmd-checkout.c b/cmd-checkout.c @@ -53,9 +53,10 @@ checkout(const char *branch_name) { /* FIXME: check if repository initialized */ if (objdb->open != NULL) objdb->open(&db_ctx, "db", baseline_path); + if (dircache->open != NULL) + dircache->open(&dc_ctx, db_ctx, objdb, baseline_path); if (objdb->init != NULL) /* TO BE REMOVED */ objdb->init(db_ctx); - dircache->init(&dc_ctx, db_ctx, objdb); if (objdb->branch_if_exists(db_ctx, branch_name, &exist) == EXIT_FAILURE) { return EXIT_FAILURE; } diff --git a/cmd-commit.c b/cmd-commit.c @@ -173,13 +173,14 @@ cmd_commit(int argc, char **argv) dircache_simple_get_ops(&dircache); if (objdb->open != NULL) objdb->open(&db_ctx, "db", ".baseline"); + if (dircache->open != NULL) + dircache->open(&dc_ctx, db_ctx, objdb, ".baseline"); if (objdb->init != NULL) /* TO BE REMOVED */ objdb->init(db_ctx); if (getcwd(cwd, PATH_MAX) == NULL) { fprintf(stderr, "baseline: error, failed to get the current working directory.\n"); return EXIT_FAILURE; } - dircache->init(&dc_ctx, db_ctx, objdb); if (dircache->commit(dc_ctx, msg_file) == EXIT_FAILURE) fprintf(stderr, "baseline: error, failed to commit your changes.\n"); if (objdb->close != NULL) objdb->close(db_ctx); diff --git a/cmd-init.c b/cmd-init.c @@ -25,83 +25,57 @@ #include <err.h> /* errx(3) */ #include "defaults.h" +#include "session.h" #include "config.h" -#include "objdb.h" -#include "dircache.h" -#include "common.h" #include "cmd.h" -extern int objdb_baseline_get_ops(struct objdb_ops **); -extern int dircache_simple_get_ops(struct dircache_ops **); - -int cmd_init(int, char **); - /* * creates a new repository in the given path. */ static int -init(const char *path) { +init(struct session *s) { char *baseline_path, *config_path; - /* int cfd; */ - struct dircache_ops *dircache; - struct dircache_ctx *dc_ctx; - struct objdb_ops *objdb; - struct objdb_ctx *db_ctx; - objdb_baseline_get_ops(&objdb); - dircache_simple_get_ops(&dircache); - asprintf(&baseline_path, "%s/%s", path, BASELINE_DIR); /* create '.baseline' dir */ + asprintf(&baseline_path, "%s/%s", s->cwd, BASELINE_DIR); if (mkdir(baseline_path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) { return EXIT_FAILURE; } /* create '.baseline/config file */ asprintf(&config_path, "%s/config", baseline_path); -/* - if ((cfd = open(config_path, O_CREAT | O_TRUNC | O_WRONLY)) == -1) { - return EXIT_FAILURE; - } - close(cfd); -*/ if (baseline_config_create(config_path) == EXIT_FAILURE) return EXIT_FAILURE; /* FIXME: error checks */ + /* let objdb initialize it's structures too */ - if (objdb->open != NULL) - objdb->open(&db_ctx, "db", baseline_path); - if (objdb->init != NULL) /* TO BE REMOVED */ - objdb->init(db_ctx); + s->db_ops->open(&(s->db_ctx), BASELINE_DB, baseline_path); + s->db_ops->init(s->db_ctx); /* as well as dircache */ - if (dircache->init != NULL) - dircache->init(&dc_ctx, db_ctx, objdb); - if (objdb->close != NULL) - objdb->close(db_ctx); + s->dc_ops->open(&(s->dc_ctx), s->db_ctx, s->db_ops, baseline_path); + s->dc_ops->init(s->dc_ctx); + free(config_path); free(baseline_path); - free(objdb); - free(dircache); return EXIT_SUCCESS; } int cmd_init(int argc, char **argv) { - char cwd[PATH_MAX+1]; - char *baseline_dir = NULL; - const char *repo; + struct session s; - repo = baseline_repo_get_rootdir(); - if (repo != NULL) + baseline_session_begin(&s, SESSION_NONINIT); + s.repo_rootdir = baseline_repo_get_rootdir(); + + if (s.repo_rootdir != NULL) errx(EXIT_SUCCESS, "repository already initialized."); - if (getcwd(cwd, sizeof(cwd)) == NULL) - errx(EXIT_FAILURE, "error, can not read current directory."); - asprintf(&baseline_dir, "%s/%s", cwd, BASELINE_DIR); - if (exists(baseline_dir)) + if (exists(s.repo_baselinedir)) errx(EXIT_FAILURE, "error, corrupted repository already exists."); - free(baseline_dir); - if (init(cwd) == EXIT_FAILURE) + if (init(&s) == EXIT_FAILURE) errx(EXIT_FAILURE, "error, could not initialize repository."); - printf("baseline: repository successfully initialized at \'%s\'.\n", cwd); + printf("baseline: repository successfully initialized at \'%s\'.\n", s.cwd); + + baseline_session_end(&s); return EXIT_SUCCESS; } diff --git a/common.c b/common.c @@ -24,9 +24,12 @@ #include <sys/stat.h> #include "defaults.h" +#include "common.h" + /* cache the repository root dir for future calls of baseline_repo_get_rootdir() */ static char *repo_rootdir = NULL; +static char *repo_baselinedir = NULL; /* repo_rootdir/BASELINE_DIR */ int exists(const char *f) @@ -93,12 +96,12 @@ baseline_repo_get_rootdir() } if (i == -1) { if (baseline_validate_repo(cwd)) - asprintf(&repo_rootdir, "/"); + repo_rootdir = strdup("/"); else return NULL; } else { - asprintf(&repo_rootdir, "%s", cwd); + repo_rootdir = strdup(cwd); } #ifdef DEBUG printf("repository root dir: %s\n", repo_rootdir); @@ -106,3 +109,14 @@ baseline_repo_get_rootdir() return repo_rootdir; } +const char* +baseline_repo_get_baselinedir() +{ + const char *root_dir; + if (repo_baselinedir != NULL) + return repo_baselinedir; + root_dir = baseline_repo_get_rootdir(); + asprintf(&repo_baselinedir, "%s/%s", root_dir, BASELINE_DIR); + return repo_baselinedir; +} + diff --git a/common.h b/common.h @@ -20,5 +20,6 @@ int exists(const char *); int dir_exists(const char *); const char* baseline_repo_get_rootdir(); +const char* baseline_repo_get_baselinedir(); #endif diff --git a/dircache-simple.c b/dircache-simple.c @@ -29,7 +29,9 @@ #include "dircache.h" int dircache_simple_get_ops(struct dircache_ops **); -static int simple_init(struct dircache_ctx **, struct objdb_ctx *, struct objdb_ops *); +static int simple_open(struct dircache_ctx **, struct objdb_ctx *, struct objdb_ops *, const char *); +static int simple_close(struct dircache_ctx *); +static int simple_init(struct dircache_ctx *); static int simple_insert(struct dircache_ctx *, const char *); static int simple_checkout(struct dircache_ctx *, const char *); static int simple_commit(struct dircache_ctx *, const char *); @@ -37,6 +39,8 @@ static int simple_commit(struct dircache_ctx *, const char *); static struct dircache_ops simple_ops = { .name = "simple", .version = "1.0", + .open = simple_open, + .close = simple_close, .init = simple_init, .insert = simple_insert, .remove = NULL, @@ -58,7 +62,26 @@ dircache_simple_get_ops(struct dircache_ops **ops) } static int -simple_init(struct dircache_ctx **dc_ctx, struct objdb_ctx *db_ctx, struct objdb_ops *db_ops) +simple_open(struct dircache_ctx **dc_ctx, struct objdb_ctx *db_ctx, struct objdb_ops *db_ops, const char *path) +{ + if (dc_ctx == NULL || db_ctx == NULL) + return EXIT_FAILURE; + *dc_ctx = (struct dircache_ctx *)malloc(sizeof(struct dircache_ctx)); + (*dc_ctx)->db_ctx = db_ctx; + (*dc_ctx)->db_ops = db_ops; + asprintf(&((*dc_ctx)->dc_path), "%s", path); + return EXIT_SUCCESS; +} + +static int +simple_close(struct dircache_ctx *dc_ctx) +{ + /* TODO */ + return EXIT_SUCCESS; +} + +static int +simple_init(struct dircache_ctx *dc_ctx) { char *branch_name = NULL, *branch_path; char *dc_path; @@ -66,11 +89,11 @@ simple_init(struct dircache_ctx **dc_ctx, struct objdb_ctx *db_ctx, struct objdb size_t size = 0; struct stat s; FILE *branch_fp; - if (dc_ctx == NULL || db_ctx == NULL) + + if (dc_ctx == NULL) return EXIT_FAILURE; - /* FIXME: use get baseline path 'common' function */ - asprintf(&dc_path, "%s/%s", ".baseline", "dircache"); - asprintf(&branch_path, "%s/branch", ".baseline"); + asprintf(&dc_path, "%s/%s", dc_ctx->dc_path, "dircache"); + asprintf(&branch_path, "%s/branch", dc_ctx->dc_path); /* check if '.baseline/dircache' dir exists */ if (stat(dc_path, &s) == -1) { /* create '.baseline/dircache' dir */ @@ -93,13 +116,13 @@ simple_init(struct dircache_ctx **dc_ctx, struct objdb_ctx *db_ctx, struct objdb } else { asprintf(&branch_name, "%s", DEFAULT_BRANCH); - if (db_ops->branch_if_exists(db_ctx, branch_name, &exist) == EXIT_FAILURE) { + if (dc_ctx->db_ops->branch_if_exists(dc_ctx->db_ctx, branch_name, &exist) == EXIT_FAILURE) { retval = EXIT_FAILURE; free(branch_name); goto ret; } if (!exist) - db_ops->branch_create(db_ctx, branch_name); + dc_ctx->db_ops->branch_create(dc_ctx->db_ctx, branch_name); /* create '.baseline/branch' file */ if ((branch_fp = fopen(branch_path, "w")) == NULL) { retval = EXIT_FAILURE; @@ -108,9 +131,6 @@ simple_init(struct dircache_ctx **dc_ctx, struct objdb_ctx *db_ctx, struct objdb fprintf(branch_fp, branch_name); fclose(branch_fp); } - *dc_ctx = (struct dircache_ctx *)malloc(sizeof(struct dircache_ctx)); - (*dc_ctx)->db_ctx = db_ctx; - (*dc_ctx)->db_ops = db_ops; ret: free(dc_path); free(branch_path); @@ -175,7 +195,7 @@ simple_insert(struct dircache_ctx *dc_ctx, const char *path) #ifdef DEBUG printf("[DEBUG] dircache: created file %s\n", cache_path); #endif - fprintf(fp, "F %s %o\n", objid, fs.st_mode); + fprintf(fp, "F %s %06o\n", objid, fs.st_mode); fclose(fp); free(cache_path); } @@ -376,7 +396,7 @@ simple_commit(struct dircache_ctx *dc_ctx, const char *msgfile) return EXIT_FAILURE; if ((fp = fopen(path, "w")) == NULL) return EXIT_FAILURE; - fprintf(fp, "%c %s %o", 'D', objid, s.st_mode); + fprintf(fp, "%c %s %06o", 'D', objid, s.st_mode); fclose(fp); } free(path); diff --git a/dircache.h b/dircache.h @@ -21,6 +21,7 @@ #include "objdb.h" struct dircache_ctx { + char *dc_path; struct objdb_ctx *db_ctx; struct objdb_ops *db_ops; }; @@ -28,7 +29,9 @@ struct dircache_ctx { struct dircache_ops { char *name; char *version; - int (*init)(struct dircache_ctx **, struct objdb_ctx *, struct objdb_ops *); + int (*open)(struct dircache_ctx **, struct objdb_ctx *, struct objdb_ops *, const char *); + int (*close)(struct dircache_ctx *); + int (*init)(struct dircache_ctx *); int (*insert)(struct dircache_ctx *, const char *); int (*remove)(struct dircache_ctx *, const char *); int (*commit)(struct dircache_ctx *, const char *); diff --git a/objdb-fs.c b/objdb-fs.c @@ -70,11 +70,11 @@ static const struct objdb_ops baseline_objdb_ops = { #define N_MAINDIRS 5 static const char *main_dirs[] = { - BASELINE_DIR "/" BASELINE_DB "/files", - BASELINE_DIR "/" BASELINE_DB "/dirs", - BASELINE_DIR "/" BASELINE_DB "/commits", - BASELINE_DIR "/" BASELINE_DB "/branches", - BASELINE_DIR "/" BASELINE_DB "/tags" + "files", + "dirs", + "commits", + "branches", + "tags" }; int @@ -101,21 +101,6 @@ get_objdb_dir(struct objdb_ctx *ctx) } static int -mkdir_ifn_exists(const char *path) -{ - struct stat s; - /* TODO: check if path is writable */ - if (stat(path, &s) == 0) { - if (S_ISDIR(s.st_mode)) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) - return EXIT_SUCCESS; - return EXIT_FAILURE; -} - -static int objdb_bl_open(struct objdb_ctx **ctx, const char *db_name, const char *db_path) { if (ctx == NULL) @@ -142,24 +127,28 @@ objdb_bl_close(struct objdb_ctx *ctx) static int objdb_bl_init(struct objdb_ctx *ctx) { - char *db_dir_name; - int i, retval; + char *db_dir_name = NULL, *maindir = NULL; + int i, retval = EXIT_FAILURE; struct stat s; - retval = EXIT_FAILURE; - db_dir_name = NULL; /* check if path exists */ if (stat(ctx->db_path, &s) == -1) goto ret; db_dir_name = get_objdb_dir(ctx); - if (mkdir_ifn_exists(db_dir_name) == EXIT_FAILURE) + if (mkdir(db_dir_name, S_IRUSR | S_IWUSR | S_IXUSR) != 0) goto ret; /* try to create main sub-dirs as well */ for (i=0 ; i<N_MAINDIRS ; i++) { - if (mkdir_ifn_exists(main_dirs[i]) == EXIT_FAILURE) + asprintf(&maindir, "%s/%s", db_dir_name, main_dirs[i]); + if (mkdir(maindir, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { + free(maindir); + printf("HERE\n"); goto ret; + } + free(maindir); } + retval = EXIT_SUCCESS; ret: - if(db_dir_name != NULL) + if (db_dir_name != NULL) free(db_dir_name); return retval; } @@ -204,6 +193,9 @@ objdb_bl_insert_from_file(struct objdb_ctx *ctx, enum objdb_type type, const cha else if (type == T_COMMIT) { len = asprintf(&full_path, "%s/%s", db_dir_name, "commits"); } + else if (type == T_TAG) { + len = asprintf(&full_path, "%s/%s", db_dir_name, "tags"); + } else { len = asprintf(&full_path, "%s", db_dir_name); } @@ -321,12 +313,12 @@ objdb_bl_dir_insert_object(struct objdb_ctx *ctx, struct objdb_dirhandle *handle /* TODO: check if obj exists! */ if (type == T_FILE) { /* FIXME: non-portable code */ - len = asprintf(&entry, "%c %s %o %s\n", 'F', objid, mode, name); + len = asprintf(&entry, "%c %s %06o %s\n", 'F', objid, mode, name); write(handle->id, entry, len); } else if (type == T_DIR) { /* FIXME: non-portable code */ - len = asprintf(&entry, "%c %s %o %s\n", 'D', objid, mode, name); + len = asprintf(&entry, "%c %s %06o %s\n", 'D', objid, mode, name); write(handle->id, entry, len); } return EXIT_SUCCESS; diff --git a/objdb.h b/objdb.h @@ -23,11 +23,11 @@ enum objdb_type { T_FILE, T_DIR, T_COMMIT, + T_TAG }; struct objdb_dirhandle { int id; - /* optional */ char *name; }; diff --git a/session.c b/session.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014 Mohamed Aslan <maslan@sce.carleton.ca> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> /* EXIT_* */ +#include <limits.h> /* PATH_MAX */ +#include <unistd.h> /* getcwd(3) */ +#include <err.h> /* errx(3) */ + +#include "defaults.h" +#include "session.h" + +extern int objdb_baseline_get_ops(struct objdb_ops **); +extern int dircache_simple_get_ops(struct dircache_ops **); + +int +baseline_session_begin(struct session *s, u_int8_t options) +{ + objdb_baseline_get_ops(&(s->db_ops)); + dircache_simple_get_ops(&(s->dc_ops)); + + if (getcwd((char *)s->cwd, sizeof(s->cwd)) == NULL) + errx(EXIT_FAILURE, "error, can not read current directory."); + + if (options & SESSION_NONINIT) { + return EXIT_SUCCESS; + } + + s->repo_rootdir = baseline_repo_get_rootdir(); + s->repo_baselinedir = baseline_repo_get_baselinedir(); + + if (s->repo_rootdir == NULL) + errx(EXIT_FAILURE, "error, no repository is found."); + if (s->db_ops->open(&(s->db_ctx), BASELINE_DB, s->repo_baselinedir) == EXIT_FAILURE) + return EXIT_FAILURE; + if (s->dc_ops->open(&(s->dc_ctx), s->db_ctx, s->db_ops, s->repo_baselinedir) == EXIT_FAILURE) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +int +baseline_session_end(struct session *s) +{ + if (s->db_ops->close(s->db_ctx) == EXIT_FAILURE) + return EXIT_FAILURE; + if (s->dc_ops->close(s->dc_ctx) == EXIT_FAILURE) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} + diff --git a/session.h b/session.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014 Mohamed Aslan <maslan@sce.carleton.ca> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _SESSION_H_ +#define _SESSION_H_ + +#include "objdb.h" +#include "dircache.h" +#include "common.h" + +#define SESSION_NONINIT (1 << 0) + + +struct session { + /* operation */ + struct objdb_ops *db_ops; + struct dircache_ops *dc_ops; + /* context */ + struct objdb_ctx *db_ctx; + struct dircache_ctx *dc_ctx; + /* other */ + const char *repo_rootdir; + const char *repo_baselinedir; + const char cwd[PATH_MAX+1]; +}; + +int baseline_session_begin(struct session *, u_int8_t); +int baseline_session_end(struct session *); + +#endif