summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/file.c
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-05-20 05:13:45 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-05-20 05:13:45 +0000
commit92227c2873d2aa52cc72cac6ba11491f2ca43785 (patch)
tree882a1bd003526e597fff3b8ed9fe90a9bd50f95d /usr.bin/cvs/file.c
parent953436ae010ef8b64f902cafa1e45d52112eb747 (diff)
execute the command callback at the same time we are building
the in-memory filelist. cuts down on execution time for larger trees. "put it in!" jfb@
Diffstat (limited to 'usr.bin/cvs/file.c')
-rw-r--r--usr.bin/cvs/file.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index dbe220352f6..2161d0b3688 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.72 2005/05/20 05:01:34 jfb Exp $ */
+/* $OpenBSD: file.c,v 1.73 2005/05/20 05:13:44 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -107,8 +107,8 @@ static RCSNUM *cvs_addedrev;
TAILQ_HEAD(, cvs_ignpat) cvs_ign_pats;
+static int cvs_file_getdir(CVSFILE *, int, char *, int (*)(CVSFILE *, void *), void *);
static int cvs_load_dirinfo (CVSFILE *, int);
-static int cvs_file_getdir (CVSFILE *, int, char *);
static int cvs_file_sort (struct cvs_flist *, u_int);
static int cvs_file_cmp (const void *, const void *);
static int cvs_file_cmpname (const char *, const char *);
@@ -345,12 +345,13 @@ cvs_file_copy(CVSFILE *orig)
*/
CVSFILE*
-cvs_file_get(const char *path, int flags)
+cvs_file_get(const char *path, int flags, int (*cb)(CVSFILE *, void *),
+ void *arg)
{
char *files[1];
files[0] = path;
- return cvs_file_getspec(files, 1, flags);
+ return cvs_file_getspec(files, 1, flags, cb, arg);
}
@@ -363,7 +364,8 @@ cvs_file_get(const char *path, int flags)
* files.
*/
CVSFILE*
-cvs_file_getspec(char **fspec, int fsn, int flags)
+cvs_file_getspec(char **fspec, int fsn, int flags, int (*cb)(CVSFILE *, void *),
+ void *arg)
{
int i;
int pwd;
@@ -377,6 +379,14 @@ cvs_file_getspec(char **fspec, int fsn, int flags)
if (base == NULL)
return (NULL);
+ /* XXX - needed for some commands */
+ if (cb != NULL) {
+ if (cb(base, arg) != CVS_EX_OK) {
+ cvs_file_free(base);
+ return (NULL);
+ }
+ }
+
for (i = 0; i < fsn; i++) {
strlcpy(pcopy, fspec[i], sizeof(pcopy));
sp = pcopy;
@@ -412,10 +422,15 @@ cvs_file_getspec(char **fspec, int fsn, int flags)
if (np != NULL)
*np++;
- if (cvs_file_getdir(nf, flags, np) < 0) {
+ if (cvs_file_getdir(nf, flags, np, cb, arg) < 0) {
cvs_file_free(base);
return (NULL);
}
+ } else {
+ if (cb != NULL) {
+ if (cb(nf, arg) != CVS_EX_OK)
+ return (NULL);
+ }
}
}
@@ -591,7 +606,7 @@ cvs_load_dirinfo(CVSFILE *cf, int flags)
* is performed by cvs_file_free().
*/
static int
-cvs_file_getdir(CVSFILE *cf, int flags, char *path)
+cvs_file_getdir(CVSFILE *cf, int flags, char *path, int (*cb)(CVSFILE *, void *), void *arg)
{
int l;
int check_entry;
@@ -630,6 +645,12 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path)
if ((flags & CF_KNOWN) && (cf->cf_cvstat == CVS_FST_UNKNOWN))
return (0);
+ /* callback for the directory entry */
+ if (cb != NULL) {
+ if (cb(cf, arg) != CVS_EX_OK)
+ return (-1);
+ }
+
dirp = opendir(fpath);
if (dirp == NULL) {
cvs_log(LP_ERRNO, "failed to open directory %s", fpath);
@@ -699,6 +720,14 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path)
if (cfp->cf_type == DT_DIR) {
ndirs++;
SIMPLEQ_INSERT_TAIL(&dirs, cfp, cf_list);
+ } else {
+ /* callback for the file */
+ if (cb != NULL) {
+ if (cb(cfp, arg) != CVS_EX_OK) {
+ closedir(dirp);
+ return (-1);
+ }
+ }
}
if (path != NULL) {
@@ -743,6 +772,12 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path)
ndirs++;
SIMPLEQ_INSERT_TAIL(&dirs, cfp,
cf_list);
+ } else {
+ /* callback for the file */
+ if (cb != NULL) {
+ if (cb(cfp, arg) != CVS_EX_OK)
+ return (-1);
+ }
}
if (path != NULL)
@@ -767,7 +802,7 @@ cvs_file_getdir(CVSFILE *cf, int flags, char *path)
else
cfp->cf_flags &= ~CVS_GDIR_IGNORE;
- if (cvs_file_getdir(cfp, flags, np) < 0) {
+ if (cvs_file_getdir(cfp, flags, np, cb, arg) < 0) {
cvs_log(LP_ERROR, "failed to get %s",
CVS_FILE_NAME(cfp));
continue;