summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Allen <screwtape@froup.com>2007-05-19 17:29:52 +1000
committerYann Dirson <ydirson@altern.org>2008-03-31 16:09:13 +0200
commitdc7f8632341107da52a5604e99041da4e84fd92c (patch)
tree8303a828998904293c68b130d1fdf6c6d69fc722
parent527e493dc1a72484fb593b7c03e577ccf8eb4028 (diff)
downloadcvsps-dc7f8632341107da52a5604e99041da4e84fd92c.tar.gz
Allow the user to specify where the cache file should go.
-rw-r--r--cache.c30
-rw-r--r--cache.h1
-rw-r--r--cvsps.c12
3 files changed, 34 insertions, 9 deletions
diff --git a/cache.c b/cache.c
index 5f67a7c..06ed905 100644
--- a/cache.c
+++ b/cache.c
@@ -22,6 +22,9 @@
#define CACHE_DESCR_BOUNDARY "-=-END CVSPS DESCR-=-\n"
+/* A place to stash the cache. */
+const char * cache_path = NULL;
+
/* change this when making the on-disk cache-format invalid */
static int cache_version = 1;
@@ -33,18 +36,20 @@ static void write_patch_set_to_cache(PatchSet *);
static void parse_cache_revision(PatchSetMember *, const char *);
static void dump_patch_set(FILE *, PatchSet *);
-static FILE *cache_open(char const *mode)
+static void set_cache_path()
{
char *prefix;
- char fname[PATH_MAX];
char root[PATH_MAX];
char repository[PATH_MAX];
- FILE * fp;
+
+ /* If the path was set with -c, that'll do. */
+ if (cache_path != NULL)
+ return;
/* Get the prefix */
prefix = get_cvsps_dir();
if (!prefix)
- return NULL;
+ return;
/* Generate the full path */
strcpy(root, root_path);
@@ -53,15 +58,24 @@ static FILE *cache_open(char const *mode)
strrep(root, '/', '#');
strrep(repository, '/', '#');
- snprintf(fname, PATH_MAX, "%s/%s#%s", prefix, root, repository);
-
- if (!(fp = fopen(fname, mode)) && *mode == 'r')
+ cache_path = malloc(PATH_MAX);
+
+ snprintf(cache_path, PATH_MAX, "%s/%s#%s", prefix, root, repository);
+}
+
+static FILE *cache_open(char const *mode)
+{
+ FILE * fp;
+
+ set_cache_path();
+
+ if (!(fp = fopen(cache_path, mode)) && *mode == 'r')
{
if ((fp = fopen("CVS/cvsps.cache", mode)))
{
fprintf(stderr, "\n");
fprintf(stderr, "****WARNING**** Obsolete CVS/cvsps.cache file found.\n");
- fprintf(stderr, " New file will be re-written in ~/%s/\n", CVSPS_PREFIX);
+ fprintf(stderr, " New file will be re-written in %s\n", cache_path);
fprintf(stderr, " Old file will be ignored.\n");
fprintf(stderr, " Please manually remove the old file.\n");
fprintf(stderr, " Continuing in 5 seconds.\n");
diff --git a/cache.h b/cache.h
index 996c4bc..856d296 100644
--- a/cache.h
+++ b/cache.h
@@ -8,5 +8,6 @@
extern time_t read_cache();
extern void write_cache(time_t);
+extern const char * cache_path;
#endif /* CACHE_H */
diff --git a/cvsps.c b/cvsps.c
index 02a12dc..1fa41d2 100644
--- a/cvsps.c
+++ b/cvsps.c
@@ -583,7 +583,7 @@ static int usage(const char * str1, const char * str2)
if (str1)
debug(DEBUG_APPERROR, "\nbad usage: %s %s\n", str1, str2);
- debug(DEBUG_APPERROR, "Usage: cvsps [-h] [-x] [-u] [-z <fuzz>] [-g] [-s <range>[,<range>]] ");
+ debug(DEBUG_APPERROR, "Usage: cvsps [-h] [-x] [-u] [-c <file>] [-z <fuzz>] [-g] [-s <range>[,<range>]] ");
debug(DEBUG_APPERROR, " [-a <author>] [-f <file>] [-d <date1> [-d <date2>]] ");
debug(DEBUG_APPERROR, " [-b <branch>] [-l <regex>] [-r <tag> [-r <tag>]] ");
debug(DEBUG_APPERROR, " [-p <directory>] [-v] [-t] [--norc] [--summary-first]");
@@ -596,6 +596,7 @@ static int usage(const char * str1, const char * str2)
debug(DEBUG_APPERROR, " -h display this informative message");
debug(DEBUG_APPERROR, " -x ignore (and rebuild) cvsps.cache file");
debug(DEBUG_APPERROR, " -u update cvsps.cache file");
+ debug(DEBUG_APPERROR, " -c <file> store cvsps.cache in given file");
debug(DEBUG_APPERROR, " -z <fuzz> set the timestamp fuzz factor for identifying patch sets");
debug(DEBUG_APPERROR, " -g generate diffs of the selected patch sets");
debug(DEBUG_APPERROR, " -s <patch set>[-[<patch set>]][,<patch set>...] restrict patch sets by id");
@@ -772,6 +773,15 @@ static int parse_args(int argc, char *argv[])
continue;
}
+ if (strcmp(argv[i], "-c") == 0)
+ {
+ if (++i >= argc)
+ return usage("argument to -c missing", "");
+
+ cache_path = argv[i++];
+ continue;
+ }
+
if (strcmp(argv[i], "-b") == 0)
{
if (++i >= argc)