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

Annotation of src/usr.bin/cvs/edit.c, Revision 1.15

1.15    ! xsa         1: /*     $OpenBSD: edit.c,v 1.14 2007/01/02 13:51:13 xsa Exp $   */
1.1       jfb         2: /*
1.15    ! xsa         3:  * Copyright (c) 2006, 2007 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         4:  *
1.14      xsa         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.
                      8:  *
                      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.11      xsa        18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
1.14      xsa        22: #include "remote.h"
1.1       jfb        23:
1.14      xsa        24: static void    cvs_editors_local(struct cvs_file *);
1.15    ! xsa        25: static void    cvs_unedit_local(struct cvs_file *);
1.1       jfb        26:
                     27: struct cvs_cmd cvs_cmd_editors = {
1.14      xsa        28:        CVS_OP_EDITORS, 0, "editors",
1.1       jfb        29:        { },
1.14      xsa        30:        "See who is editing a watched file",
1.3       xsa        31:        "[-lR] [file ...]",
1.1       jfb        32:        "lR",
                     33:        NULL,
1.14      xsa        34:        cvs_editors
1.1       jfb        35: };
                     36:
1.15    ! xsa        37: struct cvs_cmd cvs_cmd_unedit = {
        !            38:        CVS_OP_UNEDIT, 0, "unedit",
        !            39:        { },
        !            40:        "Undo an edit command",
        !            41:        "[-lR] [file ...]",
        !            42:        "lR",
        !            43:        NULL,
        !            44:        cvs_unedit
        !            45: };
        !            46:
1.14      xsa        47: int
                     48: cvs_editors(int argc, char **argv)
1.1       jfb        49: {
1.12      xsa        50:        int ch;
1.14      xsa        51:        int flags;
                     52:        struct cvs_recursion cr;
                     53:
                     54:        flags = CR_RECURSE_DIRS;
1.1       jfb        55:
1.14      xsa        56:        while ((ch = getopt(argc, argv, cvs_cmd_editors.cmd_opts)) != -1) {
1.1       jfb        57:                switch (ch) {
                     58:                case 'l':
1.14      xsa        59:                        flags &= ~CR_RECURSE_DIRS;
1.1       jfb        60:                        break;
                     61:                case 'R':
                     62:                        break;
                     63:                default:
1.14      xsa        64:                        fatal("%s", cvs_cmd_editors.cmd_synopsis);
1.1       jfb        65:                }
                     66:        }
                     67:
1.14      xsa        68:        argc -= optind;
                     69:        argv += optind;
1.1       jfb        70:
1.14      xsa        71:        if (argc == 0)
                     72:                fatal("%s", cvs_cmd_editors.cmd_synopsis);
1.1       jfb        73:
1.14      xsa        74:        cr.enterdir = NULL;
                     75:        cr.leavedir = NULL;
1.1       jfb        76:
1.14      xsa        77:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                     78:                cr.fileproc = cvs_client_sendfile;
                     79:
                     80:                if (!(flags & CR_RECURSE_DIRS))
                     81:                        cvs_client_send_request("Argument -l");
                     82:        } else {
                     83:                cr.fileproc = cvs_editors_local;
                     84:        }
1.1       jfb        85:
1.14      xsa        86:        cr.flags = flags;
1.9       xsa        87:
1.14      xsa        88:        cvs_file_run(argc, argv, &cr);
1.9       xsa        89:
1.14      xsa        90:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                     91:                cvs_client_send_files(argv, argc);
                     92:                cvs_client_senddir(".");
                     93:                cvs_client_send_request("editors");
                     94:                cvs_client_get_responses();
1.9       xsa        95:        }
                     96:
1.14      xsa        97:        return (0);
                     98: }
1.9       xsa        99:
1.15    ! xsa       100: int
        !           101: cvs_unedit(int argc, char **argv)
        !           102: {
        !           103:        int ch;
        !           104:        int flags;
        !           105:        struct cvs_recursion cr;
        !           106:
        !           107:        flags = CR_RECURSE_DIRS;
        !           108:
        !           109:        while ((ch = getopt(argc, argv, cvs_cmd_unedit.cmd_opts)) != -1) {
        !           110:                switch (ch) {
        !           111:                case 'l':
        !           112:                        flags &= ~CR_RECURSE_DIRS;
        !           113:                        break;
        !           114:                case 'R':
        !           115:                        break;
        !           116:                default:
        !           117:                        fatal("%s", cvs_cmd_unedit.cmd_synopsis);
        !           118:                }
        !           119:        }
        !           120:
        !           121:        argc -= optind;
        !           122:        argv += optind;
        !           123:
        !           124:        if (argc == 0)
        !           125:                fatal("%s", cvs_cmd_unedit.cmd_synopsis);
        !           126:
        !           127:        cr.enterdir = NULL;
        !           128:        cr.leavedir = NULL;
        !           129:
        !           130:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !           131:                cr.fileproc = cvs_client_sendfile;
        !           132:
        !           133:                if (!(flags & CR_RECURSE_DIRS))
        !           134:                        cvs_client_send_request("Argument -l");
        !           135:        } else {
        !           136:                cr.fileproc = cvs_unedit_local;
        !           137:        }
        !           138:
        !           139:        cr.flags = flags;
        !           140:
        !           141:        cvs_file_run(argc, argv, &cr);
        !           142:
        !           143:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !           144:                cvs_client_send_files(argv, argc);
        !           145:                cvs_client_senddir(".");
        !           146:                cvs_client_send_request("unedit");
        !           147:                cvs_client_get_responses();
        !           148:        }
        !           149:
        !           150:        return (0);
        !           151: }
        !           152:
1.14      xsa       153: static void
                    154: cvs_editors_local(struct cvs_file *cf)
                    155: {
1.15    ! xsa       156: }
        !           157:
        !           158: static void
        !           159: cvs_unedit_local(struct cvs_file *cf)
        !           160: {
        !           161:        FILE *fp;
        !           162:        struct stat st;
        !           163:        struct tm *t;
        !           164:        time_t now;
        !           165:        char *bfpath, *fdate;
        !           166:
        !           167:        if (cvs_noexec == 1)
        !           168:                return;
        !           169:
        !           170:        bfpath = xmalloc(MAXPATHLEN);
        !           171:        if (cvs_path_cat(CVS_PATH_BASEDIR, cf->file_name, bfpath,
        !           172:            MAXPATHLEN) >= MAXPATHLEN)
        !           173:                fatal("cvs_unedit_local: truncation");
        !           174:
        !           175:        if (stat(bfpath, &st) == -1) {
        !           176:                xfree(bfpath);
        !           177:                return;
        !           178:        }
        !           179:
        !           180:        /* XXX: compare cf->file_path and bfpath */
        !           181:
        !           182:        cvs_rename(bfpath, cf->file_path);
        !           183:        xfree(bfpath);
        !           184:
        !           185:        if ((fp = fopen(CVS_PATH_NOTIFY, "a")) == NULL)
        !           186:                fatal("cvs_unedit_local: fopen: `%s': %s",
        !           187:                    CVS_PATH_NOTIFY, strerror(errno));
        !           188:
        !           189:        (void)time(&now);
        !           190:        if ((t = gmtime(&now)) == NULL)
        !           191:                fatal("gmtime failed");
        !           192:
        !           193:        fdate = asctime(t);
        !           194:
        !           195:        (void)fprintf(fp, "U%s\t%s GMT\t%s\t%s\t\n",
        !           196:            cf->file_name, fdate, current_cvsroot->cr_host, cf->file_wd);
        !           197:
        !           198:        (void)fclose(fp);
        !           199:
        !           200:        /* XXX: Update revision number in CVS/Entries from CVS/Baserev */
1.1       jfb       201: }