[BACK]Return to update.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/update.c, Revision 1.2

1.1       jfb         1: /*     $OpenBSD$       */
                      2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27: #include <sys/param.h>
                     28: #include <sys/stat.h>
                     29:
                     30: #include <errno.h>
                     31: #include <stdio.h>
                     32: #include <fcntl.h>
                     33: #include <stdlib.h>
                     34: #include <unistd.h>
                     35: #include <string.h>
                     36: #include <sysexits.h>
                     37:
                     38: #include "cvs.h"
                     39: #include "rcs.h"
                     40: #include "log.h"
                     41:
                     42: extern char *__progname;
                     43:
                     44: extern struct cvsroot *cvs_root;
                     45:
                     46:
1.2     ! jfb        47: int  cvs_update_file  (CVSFILE *, void *);
        !            48: int  cvs_update_prune (CVSFILE *, void *);
        !            49:
        !            50:
        !            51:
        !            52:
1.1       jfb        53: /*
                     54:  * cvs_update()
                     55:  *
                     56:  * Handle the `cvs update' command.
1.2     ! jfb        57:  * Returns 0 on success, or the appropriate exit code on error.
1.1       jfb        58:  */
                     59:
                     60: int
                     61: cvs_update(int argc, char **argv)
                     62: {
1.2     ! jfb        63:        int ch, i, flags;
        !            64:        struct cvs_file *cf;
        !            65:
        !            66:        cf = NULL;
        !            67:        flags = CF_SORT|CF_RECURSE|CF_IGNORE;
1.1       jfb        68:
                     69:        while ((ch = getopt(argc, argv, "ACD:dflPpQqRr:")) != -1) {
                     70:                switch (ch) {
                     71:                case 'A':
                     72:                case 'C':
                     73:                case 'D':
                     74:                case 'd':
                     75:                case 'f':
1.2     ! jfb        76:                        break;
1.1       jfb        77:                case 'l':
1.2     ! jfb        78:                        flags &= ~CF_RECURSE;
        !            79:                        break;
1.1       jfb        80:                case 'P':
                     81:                case 'p':
                     82:                case 'Q':
                     83:                case 'q':
1.2     ! jfb        84:                        break;
1.1       jfb        85:                case 'R':
1.2     ! jfb        86:                        flags |= CF_RECURSE;
        !            87:                        break;
1.1       jfb        88:                case 'r':
                     89:                        break;
                     90:                default:
                     91:                        return (EX_USAGE);
                     92:                }
                     93:        }
                     94:
                     95:        argc -= optind;
                     96:        argv += optind;
1.2     ! jfb        97:
        !            98:        if (argc == 0) {
        !            99:                cf = cvs_file_get(".", flags);
        !           100:        }
        !           101:        else {
        !           102:                /* don't perform ignore on explicitly listed files */
        !           103:                flags &= ~CF_IGNORE;
        !           104:
        !           105:                for (i = 0; i < argc; i++) {
        !           106:                        cf = cvs_file_get(argv[i], flags);
        !           107:                }
        !           108:        }
        !           109:
        !           110:        cvs_file_examine(cf, cvs_update_file, NULL);
        !           111:
        !           112:        cvs_client_senddir(cf->cf_path);
        !           113:        cvs_client_sendreq(CVS_REQ_UPDATE, NULL, 1);
        !           114:
        !           115:        return (0);
        !           116: }
        !           117:
        !           118:
        !           119: /*
        !           120:  * cvs_update_file()
        !           121:  *
        !           122:  * Diff a single file.
        !           123:  */
        !           124:
        !           125: int
        !           126: cvs_update_file(CVSFILE *cf, void *arg)
        !           127: {
        !           128:        char *dir, *repo, rcspath[MAXPATHLEN];
        !           129:        RCSFILE *rf;
        !           130:        struct cvsroot *root;
        !           131:        struct cvs_ent *entp;
        !           132:
        !           133:        cvs_log(LP_DEBUG, "%s: updating %s", __func__, cf->cf_path);
        !           134:
        !           135:        if (cf->cf_type == DT_DIR) {
        !           136:                root = cf->cf_ddat->cd_root;
        !           137:                if ((cf->cf_parent == NULL) ||
        !           138:                    (root != cf->cf_parent->cf_ddat->cd_root)) {
        !           139:                        cvs_client_connect(root);
        !           140:                        /* XXX temporary hack */
        !           141:                        cvs_root = root;
        !           142:                }
        !           143:
        !           144:                cvs_client_senddir(cf->cf_path);
        !           145:                return (0);
        !           146:        }
        !           147:        else
        !           148:                root = cf->cf_parent->cf_ddat->cd_root;
        !           149:
        !           150:        rf = NULL;
        !           151:        if (cf->cf_parent != NULL) {
        !           152:                dir = cf->cf_parent->cf_path;
        !           153:                repo = cf->cf_parent->cf_ddat->cd_repo;
        !           154:        }
        !           155:        else {
        !           156:                dir = ".";
        !           157:                repo = NULL;
        !           158:        }
        !           159:
        !           160:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
        !           161:                if (root->cr_method == CVS_METHOD_LOCAL)
        !           162:                        cvs_printf("? %s\n", cf->cf_path);
        !           163:                else
        !           164:                        cvs_client_sendreq(CVS_REQ_QUESTIONABLE,
        !           165:                            cf->cf_name, 0);
        !           166:                return (0);
        !           167:        }
        !           168:
        !           169:        entp = cvs_ent_getent(cf->cf_path);
        !           170:        if (entp == NULL)
        !           171:                return (-1);
        !           172:
        !           173:        if ((root->cr_method != CVS_METHOD_LOCAL) &&
        !           174:            (cvs_client_sendentry(entp) < 0)) {
        !           175:                cvs_ent_free(entp);
        !           176:                return (-1);
        !           177:        }
        !           178:
        !           179:        if (root->cr_method != CVS_METHOD_LOCAL) {
        !           180:                switch (cf->cf_cvstat) {
        !           181:                case CVS_FST_UPTODATE:
        !           182:                        cvs_client_sendreq(CVS_REQ_UNCHANGED, cf->cf_name, 0);
        !           183:                        break;
        !           184:                case CVS_FST_ADDED:
        !           185:                case CVS_FST_MODIFIED:
        !           186:                        cvs_client_sendreq(CVS_REQ_MODIFIED, cf->cf_name, 0);
        !           187:                        cvs_sendfile(cf->cf_path);
        !           188:                        break;
        !           189:                default:
        !           190:                        return (-1);
        !           191:                }
        !           192:
        !           193:                cvs_ent_free(entp);
        !           194:                return (0);
        !           195:        }
        !           196:
        !           197:        snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
        !           198:            root->cr_dir, repo, cf->cf_path, RCS_FILE_EXT);
        !           199:
        !           200:        rf = rcs_open(rcspath, RCS_MODE_READ);
        !           201:        if (rf == NULL) {
        !           202:                cvs_ent_free(entp);
        !           203:                return (-1);
        !           204:        }
        !           205:
        !           206:        rcs_close(rf);
        !           207:        cvs_ent_free(entp);
        !           208:        return (0);
        !           209: }
        !           210:
        !           211:
        !           212: /*
        !           213:  * cvs_update_prune()
        !           214:  *
        !           215:  * Prune all directories which contain no more files known to CVS.
        !           216:  */
        !           217:
        !           218: int
        !           219: cvs_update_prune(CVSFILE *cf, void *arg)
        !           220: {
1.1       jfb       221:
                    222:        return (0);
                    223: }