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

1.59    ! joris       1: /*     $OpenBSD$       */
1.1       jfb         2: /*
1.59    ! joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.59    ! joris       5:  * Permission to use, copy, modify, and distribute this software for any
        !             6:  * purpose with or without fee is hereby granted, provided that the above
        !             7:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         8:  *
1.59    ! joris       9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.51      xsa        18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
1.59    ! joris      22: #include "diff.h"
1.4       jfb        23: #include "proto.h"
1.1       jfb        24:
1.59    ! joris      25: int    cvs_update(int, char **);
1.18      joris      26:
1.29      jfb        27: struct cvs_cmd cvs_cmd_update = {
                     28:        CVS_OP_UPDATE, CVS_REQ_UPDATE, "update",
                     29:        { "up", "upd" },
                     30:        "Bring work tree in sync with repository",
                     31:        "[-ACdflPpR] [-D date | -r rev] [-I ign] [-j rev] [-k mode] "
                     32:        "[-t id] ...",
1.35      xsa        33:        "ACD:dfI:j:k:lPpQqRr:t:",
1.29      jfb        34:        NULL,
1.59    ! joris      35:        cvs_update
1.18      joris      36: };
1.2       jfb        37:
1.59    ! joris      38: int
        !            39: cvs_update(int argc, char **argv)
1.1       jfb        40: {
1.18      joris      41:        int ch;
1.59    ! joris      42:        char *arg = ".";
        !            43:        struct cvs_recursion cr;
1.2       jfb        44:
1.59    ! joris      45:        while ((ch = getopt(argc, argv, cvs_cmd_update.cmd_opts)) != -1) {
1.1       jfb        46:                switch (ch) {
                     47:                case 'A':
1.24      joris      48:                        break;
1.1       jfb        49:                case 'C':
                     50:                case 'D':
1.32      xsa        51:                        break;
1.1       jfb        52:                case 'd':
1.24      joris      53:                        break;
1.1       jfb        54:                case 'f':
1.2       jfb        55:                        break;
1.35      xsa        56:                case 'I':
                     57:                        break;
                     58:                case 'j':
                     59:                        break;
                     60:                case 'k':
                     61:                        break;
1.1       jfb        62:                case 'l':
1.2       jfb        63:                        break;
1.1       jfb        64:                case 'P':
1.24      joris      65:                        break;
1.1       jfb        66:                case 'p':
1.27      xsa        67:                        break;
1.1       jfb        68:                case 'Q':
                     69:                case 'q':
1.2       jfb        70:                        break;
1.1       jfb        71:                case 'R':
1.2       jfb        72:                        break;
1.1       jfb        73:                case 'r':
                     74:                        break;
                     75:                default:
1.59    ! joris      76:                        fatal("%s", cvs_cmd_update.cmd_synopsis);
1.1       jfb        77:                }
1.32      xsa        78:        }
                     79:
1.59    ! joris      80:        argc -= optind;
        !            81:        argv += optind;
1.2       jfb        82:
1.59    ! joris      83:        cr.enterdir = cvs_update_enterdir;
        !            84:        cr.leavedir = NULL;
        !            85:        cr.local = cvs_update_local;
        !            86:        cr.remote = NULL;
1.49      joris      87:
1.59    ! joris      88:        if (argc > 0)
        !            89:                cvs_file_run(argc, argv, &cr);
        !            90:        else
        !            91:                cvs_file_run(1, &arg, &cr);
1.35      xsa        92:
1.24      joris      93:        return (0);
                     94: }
1.2       jfb        95:
1.59    ! joris      96: void
        !            97: cvs_update_enterdir(struct cvs_file *cf)
1.2       jfb        98: {
1.59    ! joris      99:        int l;
        !           100:        char *entry;
        !           101:        CVSENTRIES *entlist;
        !           102:
        !           103:        cvs_log(LP_TRACE, "cvs_update_enterdir(%s)", cf->file_path);
        !           104:
        !           105:        cvs_file_classify(cf);
        !           106:
        !           107:        if (cf->file_status == DIR_CREATE) {
        !           108:                cvs_mkpath(cf->file_path);
        !           109:                if ((cf->fd = open(cf->file_path, O_RDONLY)) == -1)
        !           110:                        fatal("cvs_update_enterdir: %s", strerror(errno));
        !           111:
        !           112:                entry = xmalloc(CVS_ENT_MAXLINELEN);
        !           113:                l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////",
        !           114:                    cf->file_name);
        !           115:                if (l == -1 || l >= CVS_ENT_MAXLINELEN)
        !           116:                        fatal("cvs_update_enterdir: overflow");
        !           117:
        !           118:                entlist = cvs_ent_open(cf->file_wd);
        !           119:                cvs_ent_add(entlist, entry);
        !           120:                cvs_ent_close(entlist, ENT_SYNC);
        !           121:                xfree(entry);
1.2       jfb       122:        }
                    123: }
                    124:
1.59    ! joris     125: void
        !           126: cvs_update_local(struct cvs_file *cf)
1.2       jfb       127: {
1.59    ! joris     128:        CVSENTRIES *entlist;
        !           129:
        !           130:        cvs_log(LP_TRACE, "cvs_update_local(%s)", cf->file_path);
1.37      joris     131:
1.59    ! joris     132:        if (cf->file_type == CVS_DIR) {
        !           133:                if (cf->file_status != FILE_UNKNOWN &&
        !           134:                    verbosity > 1)
        !           135:                        cvs_log(LP_NOTICE, "Updating %s", cf->file_path);
        !           136:                return;
1.26      jfb       137:        }
                    138:
1.59    ! joris     139:        cvs_file_classify(cf);
1.45      joris     140:
1.59    ! joris     141:        switch (cf->file_status) {
        !           142:        case FILE_UNKNOWN:
        !           143:                cvs_printf("? %s\n", cf->file_path);
1.45      joris     144:                break;
1.59    ! joris     145:        case FILE_MODIFIED:
        !           146:                if (cf->file_ent->ce_conflict != NULL)
        !           147:                        cvs_printf("C %s\n", cf->file_path);
        !           148:                else
        !           149:                        cvs_printf("M %s\n", cf->file_path);
1.45      joris     150:                break;
1.59    ! joris     151:        case FILE_ADDED:
        !           152:                cvs_printf("A %s\n", cf->file_path);
1.45      joris     153:                break;
1.59    ! joris     154:        case FILE_REMOVED:
        !           155:                cvs_printf("R %s\n", cf->file_path);
1.45      joris     156:                break;
1.59    ! joris     157:        case FILE_CONFLICT:
        !           158:                cvs_printf("C %s\n", cf->file_path);
        !           159:                break;
        !           160:        case FILE_LOST:
        !           161:        case FILE_CHECKOUT:
        !           162:        case FILE_PATCH:
        !           163:                if (cvs_checkout_file(cf, cf->file_rcs->rf_head, 0))
        !           164:                        cvs_printf("U %s\n", cf->file_path);
        !           165:                break;
        !           166:        case FILE_MERGE:
        !           167:                cvs_printf("needs merge: %s\n", cf->file_path);
        !           168:                break;
        !           169:        case FILE_UNLINK:
        !           170:                (void)unlink(cf->file_path);
        !           171:        case FILE_REMOVE_ENTRY:
        !           172:                entlist = cvs_ent_open(cf->file_wd);
        !           173:                cvs_ent_remove(entlist, cf->file_name);
        !           174:                cvs_ent_close(entlist, ENT_SYNC);
1.45      joris     175:                break;
                    176:        default:
                    177:                break;
                    178:        }
1.1       jfb       179: }