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

Annotation of src/usr.bin/cvs/admin.c, Revision 1.35

1.35    ! xsa         1: /*     $OpenBSD$       */
1.1       joris       2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
                      4:  * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
1.35    ! xsa         5:  * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       joris       6:  *
1.35    ! xsa         7:  * Permission to use, copy, modify, and distribute this software for any
        !             8:  * purpose with or without fee is hereby granted, provided that the above
        !             9:  * copyright notice and this permission notice appear in all copies.
1.1       joris      10:  *
1.35    ! xsa        11:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            12:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            13:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            14:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            15:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            16:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            17:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       joris      18:  */
                     19:
1.26      xsa        20: #include "includes.h"
1.1       joris      21:
                     22: #include "cvs.h"
                     23: #include "log.h"
1.35    ! xsa        24: #include "remote.h"
1.1       joris      25:
1.35    ! xsa        26: #define ADM_EFLAG      0x01
1.1       joris      27:
1.35    ! xsa        28: void   cvs_admin_local(struct cvs_file *);
1.15      jfb        29:
                     30: struct cvs_cmd cvs_cmd_admin = {
1.35    ! xsa        31:        CVS_OP_ADMIN, 0, "admin",
1.15      jfb        32:        { "adm", "rcs" },
                     33:        "Administrative front-end for RCS",
1.35    ! xsa        34:        "[-ILqU] [A oldfile] [-a users] [-b branch]\n"
        !            35:        "[-c string] [-e [users]] [-k mode] [-l [rev]] [-m rev:msg]\n"
        !            36:        "[-N tag[:rev]] [-n tag[:rev]] [-o rev] [-s state[:rev]]"
        !            37:        "[-t file | str]\n"
        !            38:        "[-u [rev]] file ...",
        !            39:        "A:a:b::c:e::Ik:l::Lm:N:n:o:qs:t:Uu::",
1.15      jfb        40:        NULL,
1.35    ! xsa        41:        cvs_admin
1.7       joris      42: };
                     43:
1.35    ! xsa        44: static int      runflags = 0;
        !            45: static int      lkmode = RCS_LOCK_INVAL;
        !            46: static char    *comment = NULL;
        !            47: static char    *elist = NULL;
1.7       joris      48:
1.35    ! xsa        49: int
        !            50: cvs_admin(int argc, char **argv)
1.1       joris      51: {
1.7       joris      52:        int ch;
1.35    ! xsa        53:        int flags;
        !            54:        struct cvs_recursion cr;
1.1       joris      55:
1.35    ! xsa        56:        flags = CR_RECURSE_DIRS;
1.1       joris      57:
1.35    ! xsa        58:        while ((ch = getopt(argc, argv, cvs_cmd_admin.cmd_opts)) != -1) {
1.1       joris      59:                switch (ch) {
1.35    ! xsa        60:                case 'A':
        !            61:                        break;
1.1       joris      62:                case 'a':
                     63:                        break;
                     64:                case 'b':
                     65:                        break;
                     66:                case 'c':
                     67:                        comment = optarg;
                     68:                        break;
                     69:                case 'e':
1.35    ! xsa        70:                        elist = optarg;
        !            71:                        runflags |= ADM_EFLAG;
1.1       joris      72:                        break;
                     73:                case 'I':
                     74:                        break;
                     75:                case 'k':
1.35    ! xsa        76:                        break;
        !            77:                case 'L':
        !            78:                        if (lkmode == RCS_LOCK_LOOSE) {
        !            79:                                cvs_log(LP_ERR, "-L and -U are incompatible");
        !            80:                                fatal("%s", cvs_cmd_admin.cmd_synopsis);
1.3       joris      81:                        }
1.35    ! xsa        82:                        lkmode = RCS_LOCK_STRICT;
1.1       joris      83:                        break;
                     84:                case 'l':
                     85:                        break;
1.35    ! xsa        86:                case 'm':
1.1       joris      87:                        break;
1.35    ! xsa        88:                case 'N':
1.1       joris      89:                        break;
                     90:                case 'n':
                     91:                        break;
                     92:                case 'o':
                     93:                        break;
                     94:                case 'q':
1.35    ! xsa        95:                        verbosity = 0;
1.1       joris      96:                        break;
                     97:                case 's':
                     98:                        break;
                     99:                case 't':
                    100:                        break;
                    101:                case 'U':
1.35    ! xsa       102:                        if (lkmode == RCS_LOCK_STRICT) {
        !           103:                                cvs_log(LP_ERR, "-U and -L are incompatible");
        !           104:                                fatal("%s", cvs_cmd_admin.cmd_synopsis);
1.16      jfb       105:                        }
                    106:                        lkmode = RCS_LOCK_LOOSE;
1.1       joris     107:                        break;
1.35    ! xsa       108:                case 'u':
        !           109:                        break;
1.1       joris     110:                default:
1.35    ! xsa       111:                        fatal("%s", cvs_cmd_admin.cmd_synopsis);
1.1       joris     112:                }
                    113:        }
                    114:
                    115:        argc -= optind;
                    116:        argv += optind;
                    117:
1.35    ! xsa       118:        if (argc <= 1)
        !           119:                fatal("%s", cvs_cmd_admin.cmd_synopsis);
1.16      jfb       120:
1.35    ! xsa       121:        cr.enterdir = NULL;
        !           122:        cr.leavedir = NULL;
1.25      joris     123:
1.35    ! xsa       124:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !           125:                cr.fileproc = cvs_client_sendfile;
1.1       joris     126:
1.35    ! xsa       127:                if (comment != NULL)
        !           128:                        cvs_client_send_request("Argument -c%s", comment);
1.1       joris     129:
1.35    ! xsa       130:                if (lkmode == RCS_LOCK_STRICT)
        !           131:                        cvs_client_send_request("Argument -L");
        !           132:                else if (lkmode == RCS_LOCK_LOOSE)
        !           133:                        cvs_client_send_request("Argument -U");
1.25      joris     134:
1.35    ! xsa       135:                if (verbosity == 0)
        !           136:                        cvs_client_send_request("Argument -q");
1.25      joris     137:
1.35    ! xsa       138:        } else {
        !           139:                cr.fileproc = cvs_admin_local;
1.7       joris     140:        }
1.1       joris     141:
1.35    ! xsa       142:        cr.flags = flags;
1.1       joris     143:
1.35    ! xsa       144:        cvs_file_run(argc, argv, &cr);
1.5       joris     145:
1.35    ! xsa       146:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !           147:                cvs_client_send_files(argv, argc);
        !           148:                cvs_client_senddir(".");
        !           149:                cvs_client_send_request("admin");
        !           150:                cvs_client_get_responses();
1.1       joris     151:        }
                    152:
                    153:        return (0);
                    154: }
                    155:
1.35    ! xsa       156: void
        !           157: cvs_admin_local(struct cvs_file *cf)
1.1       joris     158: {
1.35    ! xsa       159:        int i;
1.1       joris     160:
1.35    ! xsa       161:        cvs_log(LP_TRACE, "cvs_admin_local(%s)", cf->file_path);
1.14      joris     162:
1.35    ! xsa       163:        if (cf->file_type == CVS_DIR) {
        !           164:                if (verbosity > 1)
        !           165:                        cvs_log(LP_NOTICE, "Administrating %s", cf->file_name);
        !           166:                return;
1.1       joris     167:        }
                    168:
1.35    ! xsa       169:        if (cf->file_status == FILE_UNKNOWN)
        !           170:                return;
        !           171:        else if (cf->file_status == FILE_ADDED) {
        !           172:                cvs_log(LP_ERR, "cannot admin newly added file `%s'",
        !           173:                    cf->file_name);
        !           174:                return;
1.16      jfb       175:        }
1.1       joris     176:
1.35    ! xsa       177:        if (verbosity > 0)
        !           178:                cvs_printf("RCS file: %s\n", cf->file_path);
1.14      joris     179:
1.35    ! xsa       180:        if (comment != NULL)
        !           181:                rcs_comment_set(cf->file_rcs, comment);
1.19      xsa       182:
1.35    ! xsa       183:        if (elist != NULL) {
        !           184:                struct cvs_argvector *eargv;
1.1       joris     185:
1.35    ! xsa       186:                eargv = cvs_strsplit(elist, ",");
        !           187:                for (i = 0; eargv->argv[i] != NULL; i++)
        !           188:                        rcs_access_remove(cf->file_rcs, eargv->argv[i]);
1.1       joris     189:
1.35    ! xsa       190:                cvs_argv_destroy(eargv);
        !           191:        } else if (runflags & ADM_EFLAG) {
        !           192:                struct rcs_access *rap;
1.1       joris     193:
1.35    ! xsa       194:                while (!TAILQ_EMPTY(&(cf->file_rcs->rf_access))) {
        !           195:                        rap = TAILQ_FIRST(&(cf->file_rcs->rf_access));
        !           196:                        TAILQ_REMOVE(&(cf->file_rcs->rf_access), rap, ra_list);
        !           197:                        xfree(rap->ra_name);
        !           198:                        xfree(rap);
        !           199:                }
        !           200:                /* no synced anymore */
        !           201:                cf->file_rcs->rf_flags &= ~RCS_SYNCED;
        !           202:        }
1.33      xsa       203:
1.16      jfb       204:        if (lkmode != RCS_LOCK_INVAL)
1.35    ! xsa       205:                (void)rcs_lock_setmode(cf->file_rcs, lkmode);
1.29      xsa       206:
1.35    ! xsa       207:        if (verbosity > 0)
1.29      xsa       208:                cvs_printf("done\n");
1.1       joris     209: }