[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.10

1.10    ! deraadt     1: /*     $OpenBSD: update.c,v 1.9 2004/11/26 16:23:50 jfb Exp $  */
1.1       jfb         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"
1.4       jfb        41: #include "proto.h"
1.1       jfb        42:
                     43:
1.2       jfb        44: int  cvs_update_file  (CVSFILE *, void *);
                     45: int  cvs_update_prune (CVSFILE *, void *);
                     46:
                     47:
                     48:
                     49:
1.1       jfb        50: /*
                     51:  * cvs_update()
                     52:  *
                     53:  * Handle the `cvs update' command.
1.2       jfb        54:  * Returns 0 on success, or the appropriate exit code on error.
1.1       jfb        55:  */
                     56:
                     57: int
                     58: cvs_update(int argc, char **argv)
                     59: {
1.7       jfb        60:        int ch, flags;
1.2       jfb        61:
1.8       jfb        62:        flags = CF_SORT|CF_RECURSE|CF_IGNORE|CF_KNOWN|CF_NOSYMS;
1.1       jfb        63:
                     64:        while ((ch = getopt(argc, argv, "ACD:dflPpQqRr:")) != -1) {
                     65:                switch (ch) {
                     66:                case 'A':
                     67:                case 'C':
                     68:                case 'D':
                     69:                case 'd':
                     70:                case 'f':
1.2       jfb        71:                        break;
1.1       jfb        72:                case 'l':
1.2       jfb        73:                        flags &= ~CF_RECURSE;
                     74:                        break;
1.1       jfb        75:                case 'P':
                     76:                case 'p':
                     77:                case 'Q':
                     78:                case 'q':
1.2       jfb        79:                        break;
1.1       jfb        80:                case 'R':
1.2       jfb        81:                        flags |= CF_RECURSE;
                     82:                        break;
1.1       jfb        83:                case 'r':
                     84:                        break;
                     85:                default:
                     86:                        return (EX_USAGE);
                     87:                }
                     88:        }
                     89:
                     90:        argc -= optind;
                     91:        argv += optind;
1.2       jfb        92:
                     93:        if (argc == 0) {
1.7       jfb        94:                cvs_files = cvs_file_get(".", flags);
1.10    ! deraadt    95:        } else {
1.2       jfb        96:                /* don't perform ignore on explicitly listed files */
1.7       jfb        97:                flags &= ~(CF_IGNORE | CF_RECURSE | CF_SORT);
                     98:                cvs_files = cvs_file_getspec(argv, argc, flags);
1.2       jfb        99:        }
1.7       jfb       100:        if (cvs_files == NULL)
                    101:                return (EX_DATAERR);
1.2       jfb       102:
1.7       jfb       103:        cvs_file_examine(cvs_files, cvs_update_file, NULL);
1.2       jfb       104:
1.7       jfb       105:        cvs_senddir(cvs_files->cf_ddat->cd_root, cvs_files);
                    106:        cvs_sendreq(cvs_files->cf_ddat->cd_root, CVS_REQ_UPDATE, NULL);
1.2       jfb       107:
                    108:        return (0);
                    109: }
                    110:
                    111:
                    112: /*
                    113:  * cvs_update_file()
                    114:  *
                    115:  * Diff a single file.
                    116:  */
                    117:
                    118: int
                    119: cvs_update_file(CVSFILE *cf, void *arg)
                    120: {
1.9       jfb       121:        char *repo, fpath[MAXPATHLEN], rcspath[MAXPATHLEN];
1.2       jfb       122:        RCSFILE *rf;
                    123:        struct cvsroot *root;
                    124:        struct cvs_ent *entp;
                    125:
1.9       jfb       126:        cvs_file_getpath(cf, fpath, sizeof(fpath));
                    127:
1.2       jfb       128:        if (cf->cf_type == DT_DIR) {
1.6       jfb       129:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    130:                        root = cf->cf_parent->cf_ddat->cd_root;
1.9       jfb       131:                        cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    132:                            CVS_FILE_NAME(cf));
1.10    ! deraadt   133:                } else {
1.6       jfb       134:                        root = cf->cf_ddat->cd_root;
                    135:                        if ((cf->cf_parent == NULL) ||
                    136:                            (root != cf->cf_parent->cf_ddat->cd_root)) {
                    137:                                cvs_connect(root);
                    138:                        }
                    139:
                    140:                        cvs_senddir(root, cf);
1.2       jfb       141:                }
                    142:
                    143:                return (0);
1.10    ! deraadt   144:        } else
1.2       jfb       145:                root = cf->cf_parent->cf_ddat->cd_root;
                    146:
                    147:        rf = NULL;
                    148:        if (cf->cf_parent != NULL) {
                    149:                repo = cf->cf_parent->cf_ddat->cd_repo;
1.10    ! deraadt   150:        } else {
1.2       jfb       151:                repo = NULL;
                    152:        }
                    153:
                    154:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    155:                if (root->cr_method == CVS_METHOD_LOCAL)
1.9       jfb       156:                        cvs_printf("? %s\n", fpath);
1.2       jfb       157:                else
1.9       jfb       158:                        cvs_sendreq(root, CVS_REQ_QUESTIONABLE, CVS_FILE_NAME(cf));
1.2       jfb       159:                return (0);
                    160:        }
                    161:
1.9       jfb       162:        entp = cvs_ent_getent(fpath);
1.2       jfb       163:        if (entp == NULL)
                    164:                return (-1);
                    165:
                    166:        if ((root->cr_method != CVS_METHOD_LOCAL) &&
1.4       jfb       167:            (cvs_sendentry(root, entp) < 0)) {
1.2       jfb       168:                cvs_ent_free(entp);
                    169:                return (-1);
                    170:        }
                    171:
                    172:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    173:                switch (cf->cf_cvstat) {
                    174:                case CVS_FST_UPTODATE:
1.9       jfb       175:                        cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
1.2       jfb       176:                        break;
                    177:                case CVS_FST_ADDED:
                    178:                case CVS_FST_MODIFIED:
1.9       jfb       179:                        cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cf));
                    180:                        cvs_sendfile(root, fpath);
1.2       jfb       181:                        break;
                    182:                default:
                    183:                        return (-1);
                    184:                }
                    185:
                    186:                cvs_ent_free(entp);
                    187:                return (0);
                    188:        }
                    189:
                    190:        snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.9       jfb       191:            root->cr_dir, repo, fpath, RCS_FILE_EXT);
1.2       jfb       192:
                    193:        rf = rcs_open(rcspath, RCS_MODE_READ);
                    194:        if (rf == NULL) {
                    195:                cvs_ent_free(entp);
                    196:                return (-1);
                    197:        }
                    198:
                    199:        rcs_close(rf);
                    200:        cvs_ent_free(entp);
                    201:        return (0);
                    202: }
                    203:
                    204:
                    205: /*
                    206:  * cvs_update_prune()
                    207:  *
                    208:  * Prune all directories which contain no more files known to CVS.
                    209:  */
                    210:
                    211: int
                    212: cvs_update_prune(CVSFILE *cf, void *arg)
                    213: {
1.1       jfb       214:
                    215:        return (0);
                    216: }