baseline

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

commit 1f7274bc9e4d79d77d7d4ad7ebb1eabc875cff42
parent 8d6b85d960219e6416dcfa61a13ed392bd54d268
Author: Mohamed Aslan <maslan@sce.carleton.ca>
Date:   Mon,  6 Oct 2014 04:11:38 -0600

add support for -n flag in cmd-log.c

Diffstat:
Mcmd-log.c | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/cmd-log.c b/cmd-log.c @@ -15,10 +15,12 @@ */ #include <stdio.h> /* printf(3) */ -#include <stdlib.h> /* EXIT_SUCCESS */ +#include <stdlib.h> /* EXIT_SUCCESS, strtonum(3) */ #include <string.h> /* strdup(3) */ #include <time.h> /* ctime(3) */ #include <unistd.h> /* getopt(3) */ +#include <err.h> /* errx(3) */ +#include <limits.h> /* INT_MAX */ #include "cmd.h" #include "session.h" @@ -43,19 +45,27 @@ cmd_log(int argc, char **argv) { char *head = NULL, *fmtstr = NULL; char timestr[26]; - int ch, done = 0, fmt = 0, i, k = 0; + const char *errstr; + int ch, done = 0, i, k = 0, kmax = 0; + int fmt = 0, limited = 0; struct session s; struct commit *comm; baseline_session_begin(&s, 0); /* parse command line options */ - while ((ch = getopt(argc, argv, "f:")) != -1) { + while ((ch = getopt(argc, argv, "f:n:")) != -1) { switch (ch) { case 'f': fmt = 1; fmtstr = strdup(optarg); break; + case 'n': + limited = 1; + kmax = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr != NULL) + errx(EXIT_FAILURE, "error, number (%s) is %s.", optarg, errstr); + break; default: exit(EXIT_FAILURE); } @@ -72,6 +82,8 @@ cmd_log(int argc, char **argv) do { k++; + if ((limited) && (k > kmax)) + break; comm = baseline_commit_new(); s.db_ops->select_commit(s.db_ctx, head, comm); for (i = 0 ; i<strlen(fmtstr) ; i++) {