commit 1a5a06dfaa6278f25192d9892c66da011f6fdf97
parent 7ea3563926e47c2d63f21b839205f50244f729ac
Author: Mohamed Aslan <maslan@sce.carleton.ca>
Date: Mon, 26 May 2014 04:08:09 -0400
cmd-checkout now uses sessions
Diffstat:
2 files changed, 15 insertions(+), 37 deletions(-)
diff --git a/cmd-branch.c b/cmd-branch.c
@@ -39,7 +39,6 @@ cmd_branch(int argc, char **argv)
O_LISTCUR,
O_LISTALL,
O_CREATE,
- O_SWITCH
} op = O_LISTCUR;
int ch, error = 0;
struct session s;
@@ -47,7 +46,7 @@ cmd_branch(int argc, char **argv)
baseline_session_begin(&s, 0);
/* parse command line options */
- while ((ch = getopt(argc, argv, "ac:s:")) != -1) {
+ while ((ch = getopt(argc, argv, "ac:")) != -1) {
switch (ch) {
case 'a':
op = O_LISTALL;
@@ -56,8 +55,6 @@ cmd_branch(int argc, char **argv)
op = O_CREATE;
branch = strdup(optarg);
break;
- case 's':
- op = O_SWITCH;
default:
error = 1;
break;
@@ -86,8 +83,6 @@ cmd_branch(int argc, char **argv)
if (s.db_ops->branch_create(s.db_ctx, branch) == EXIT_FAILURE)
errx(EXIT_FAILURE, "error, failed to create branch \'%s\'.", branch);
break;
- case O_SWITCH:
- break;
}
baseline_session_end(&s);
diff --git a/cmd-checkout.c b/cmd-checkout.c
@@ -14,8 +14,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h> /* EXIT_FAILURE */
#include <string.h> /* strstr(3) */
@@ -25,9 +23,7 @@
#include <err.h> /* errx(3) */
#include "defaults.h"
-#include "config.h"
-#include "objdb.h"
-#include "dircache.h"
+#include "session.h"
#include "cmd.h"
extern int objdb_baseline_get_ops(struct objdb_ops **);
@@ -39,48 +35,35 @@ int cmd_branch(int, char **);
* creates a new branch.
*/
static int
-checkout(const char *branch_name) {
- char *baseline_path;
- int exist, retval = EXIT_SUCCESS;
- struct objdb_ops *objdb;
- struct objdb_ctx *db_ctx;
- struct dircache_ops *dircache;
- struct dircache_ctx *dc_ctx;
- objdb_baseline_get_ops(&objdb);
- dircache_simple_get_ops(&dircache);
- /* FIXME: get repository path correctly */
- asprintf(&baseline_path, "%s", BASELINE_DIR);
- /* 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);
- if (objdb->branch_if_exists(db_ctx, branch_name, &exist) == EXIT_FAILURE) {
+checkout(struct session *s, const char *branch_name) {
+ int exist;
+
+ if (s->db_ops->branch_if_exists(s->db_ctx, branch_name, &exist) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
if (exist)
- dircache->checkout(dc_ctx, branch_name);
+ s->dc_ops->checkout(s->dc_ctx, branch_name);
else
errx(EXIT_FAILURE, "branch \'%s\' does not exist.", branch_name);
- if (objdb->close != NULL)
- objdb->close(db_ctx);
- free(baseline_path);
- free(objdb);
- return retval;
+ return EXIT_SUCCESS;
}
int
cmd_checkout(int argc, char **argv)
{
+ struct session s;
+
+ baseline_session_begin(&s, 0);
+
if (argc == 2) { /* 1 arg */
- if (checkout(argv[1]) == EXIT_FAILURE)
+ if (checkout(&s, argv[1]) == EXIT_FAILURE)
errx(EXIT_FAILURE, "failed to checkout branch \'%s\'", argv[1]);
}
else{
errx(EXIT_FAILURE, "wrong number of parameters for command \'checkout\'");
}
+
+ baseline_session_end(&s);
return EXIT_SUCCESS;
}