baseline

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

commit f29503c149da6bec13915f2e9baa98bd70b2edb4
parent 2cc9252c7c5d8b6f2068f1fdf6f5b3f76a0e6ed7
Author: Mohamed Aslan <maslan@sce.carleton.ca>
Date:   Mon,  6 Oct 2014 15:18:23 -0600

add support in cmd-diff for one command line argument

Diffstat:
Mcmd-diff.c | 43++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/cmd-diff.c b/cmd-diff.c @@ -341,27 +341,39 @@ diff_r(struct session *s, struct dir *d1, struct dir *d2, const char *p, const c int cmd_diff(int argc, char **argv) { - char *old, *new; + char *old = NULL, *new = NULL; char *tmpdir = NULL; struct session s; struct commit *comm_old, *comm_new; struct dir *dir_old, *dir_new; - if (argc != 3) { + baseline_session_begin(&s, 0); + + if (argc == 2) { + new = strdup(argv[1]); + } + else if (argc == 3) { + old = strdup(argv[1]); + new = strdup(argv[2]); + } + else { errx(EXIT_FAILURE, "wrong number of arguments (%d)\n", argc); } - old = strdup(argv[1]); - new = strdup(argv[2]); - - baseline_session_begin(&s, 0); tmpdir = make_tmpdir(); - /* - s.db_ops->branch_get_head(s.db_ctx, s.branch, &head); - if (head == NULL) - goto ret; - */ + comm_new = baseline_commit_new(); + s.db_ops->select_commit(s.db_ctx, new, comm_new); + + dir_new = baseline_dir_new(); + s.db_ops->select_dir(s.db_ctx, comm_new->dir, dir_new); + + if (old == NULL) { + if (comm_new->n_parents > 0) + old = comm_new->parents[0]; + else + goto ret; + } comm_old = baseline_commit_new(); s.db_ops->select_commit(s.db_ctx, old, comm_old); @@ -369,19 +381,16 @@ cmd_diff(int argc, char **argv) dir_old = baseline_dir_new(); s.db_ops->select_dir(s.db_ctx, comm_old->dir, dir_old); - comm_new = baseline_commit_new(); - s.db_ops->select_commit(s.db_ctx, new, comm_new); - - dir_new = baseline_dir_new(); - s.db_ops->select_dir(s.db_ctx, comm_new->dir, dir_new); - diff_r(&s, dir_old, dir_new, "", tmpdir); baseline_dir_free(dir_old); baseline_dir_free(dir_new); +ret: remove(tmpdir); free(tmpdir); + free(old); + free(new); baseline_session_end(&s); return EXIT_SUCCESS; }