commit 9249505d9bdb3ba01c87b6f82af2f6a81ea56eb3
parent fc8fa6eaed914e7b6af7fa9f9af48a2087142a32
Author: Mohamed Aslan <maslan@sce.carleton.ca>
Date: Sun, 25 May 2014 14:51:30 -0400
cmd-commit now uses sessions
Diffstat:
3 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/cmd-commit.c b/cmd-commit.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) */
@@ -24,13 +22,10 @@
#include <err.h> /* err(3) */
#include "defaults.h"
+#include "session.h"
#include "config.h"
-#include "objdb.h"
-#include "dircache.h"
#include "cmd.h"
-extern int objdb_baseline_get_ops(struct objdb_ops **);
-extern int dircache_simple_get_ops(struct dircache_ops **);
static const char msg_head[] = {
"\n"
@@ -112,19 +107,14 @@ int
cmd_commit(int argc, char **argv)
{
char *commit_msg, *msg_file;
- char cwd[PATH_MAX];
char *exec;
const char *editor;
int ch;
int flag_msg = 0, flag_error = 0;
- struct dircache_ops *dircache;
- struct dircache_ctx *dc_ctx;
- struct objdb_ops *objdb;
- struct objdb_ctx *db_ctx;
+ struct session s;
+
+ baseline_session_begin(&s, 0);
- /* load configurations */
- if (baseline_config_load(BASELINE_DIR "/config") == EXIT_FAILURE)
- errx(EXIT_FAILURE, "failed to load configurations");
/* parse command line options */
while ((ch = getopt(argc, argv, "m:")) != -1) {
switch (ch) {
@@ -169,23 +159,12 @@ cmd_commit(int argc, char **argv)
if (process_msgfile(&msg_file) == EXIT_FAILURE)
errx(EXIT_FAILURE, "failed to process commit message");
- objdb_baseline_get_ops(&objdb);
- 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;
- }
- if (dircache->commit(dc_ctx, msg_file) == EXIT_FAILURE)
+ if (s.dc_ops->commit(s.dc_ctx, msg_file) == EXIT_FAILURE)
fprintf(stderr, "baseline: error, failed to commit your changes.\n");
- if (objdb->close != NULL) objdb->close(db_ctx);
unlink(msg_file);
free(msg_file);
+
+ baseline_session_end(&s);
return EXIT_SUCCESS;
}
diff --git a/defaults.h b/defaults.h
@@ -17,8 +17,9 @@
#ifndef DEFAULTS_H_
#define DEFAULTS_H_
-#define BASELINE_DIR ".baseline"
-#define BASELINE_DB "db"
-#define DEFAULT_BRANCH "master"
+#define BASELINE_DIR ".baseline"
+#define BASELINE_DB "db"
+#define BASELINE_CONFIGFILE "config"
+#define DEFAULT_BRANCH "master"
#endif
diff --git a/session.c b/session.c
@@ -14,12 +14,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <stdio.h> /* asprintf(3) */
#include <stdlib.h> /* EXIT_* */
#include <limits.h> /* PATH_MAX */
#include <unistd.h> /* getcwd(3) */
#include <err.h> /* errx(3) */
#include "defaults.h"
+#include "config.h"
#include "session.h"
extern int objdb_baseline_get_ops(struct objdb_ops **);
@@ -28,6 +30,8 @@ extern int dircache_simple_get_ops(struct dircache_ops **);
int
baseline_session_begin(struct session *s, u_int8_t options)
{
+ char *config = NULL;
+
objdb_baseline_get_ops(&(s->db_ops));
dircache_simple_get_ops(&(s->dc_ops));
@@ -48,6 +52,12 @@ baseline_session_begin(struct session *s, u_int8_t options)
if (s->dc_ops->open(&(s->dc_ctx), s->db_ctx, s->db_ops, s->repo_baselinedir) == EXIT_FAILURE)
return EXIT_FAILURE;
+ /* load configurations */
+ asprintf(&config, "%s/%s", s->repo_baselinedir, BASELINE_CONFIGFILE);
+ if (baseline_config_load(config) == EXIT_FAILURE)
+ errx(EXIT_FAILURE, "failed to load configurations.");
+ free(config);
+
return EXIT_SUCCESS;
}