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

Annotation of src/usr.bin/cvs/history.c, Revision 1.24

1.24    ! joris       1: /*     $OpenBSD: history.c,v 1.23 2005/07/25 12:05:43 xsa Exp $        */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.5       tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.5       tedu        6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
1.1       jfb         9:  *
1.5       tedu       10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
1.1       jfb        12:  * 2. The name of the author may not be used to endorse or promote products
1.5       tedu       13:  *    derived from this software without specific prior written permission.
1.1       jfb        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
1.5       tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/stat.h>
                     28:
                     29: #include <errno.h>
1.18      xsa        30: #include <fcntl.h>
1.1       jfb        31: #include <stdio.h>
                     32: #include <stdlib.h>
1.18      xsa        33: #include <string.h>
1.1       jfb        34: #include <unistd.h>
                     35:
                     36: #include "cvs.h"
                     37: #include "log.h"
1.3       jfb        38: #include "proto.h"
1.1       jfb        39:
1.23      xsa        40: #define CVS_HISTORY_MAXMOD     16
1.1       jfb        41:
                     42: /* history flags */
1.23      xsa        43: #define CVS_HF_A       0x01
                     44: #define CVS_HF_C       0x02
                     45: #define CVS_HF_E       0x04
                     46: #define CVS_HF_L       0x08
                     47: #define CVS_HF_M       0x10
                     48: #define CVS_HF_O       0x20
                     49: #define CVS_HF_T       0x40
                     50: #define CVS_HF_W       0x80
1.1       jfb        51:
1.23      xsa        52: #define CVS_HF_EXCL    (CVS_HF_C|CVS_HF_E|CVS_HF_M|CVS_HF_O|CVS_HF_T|CVS_HF_X)
1.1       jfb        53:
1.23      xsa        54: static int     cvs_history_init(struct cvs_cmd *, int, char **, int *);
1.21      joris      55: #if 0
1.23      xsa        56: static void    cvs_history_print(struct cvs_hent *);
1.21      joris      57: #endif
1.23      xsa        58: static int     cvs_history_pre_exec(struct cvsroot *);
1.1       jfb        59:
                     60: extern char *__progname;
                     61:
1.14      jfb        62: struct cvs_cmd cvs_cmd_history = {
                     63:        CVS_OP_HISTORY, CVS_REQ_HISTORY, "history",
                     64:        { "hi", "his" },
                     65:        "Show repository access history",
1.15      xsa        66:        "[-aceloTw] [-b str] [-D date] [-f file] [-m module] [-n module] "
                     67:        "[-p path] [-r rev] [-t tag] [-u user] [-x ACEFGMORTUW] [-z tz]",
                     68:        "ab:cD:ef:lm:n:op:r:Tt:u:wx:z:",
1.14      jfb        69:        NULL,
                     70:        0,
                     71:        cvs_history_init,
                     72:        cvs_history_pre_exec,
                     73:        NULL,
1.9       joris      74:        NULL,
                     75:        NULL,
                     76:        NULL,
                     77:        CVS_CMD_SENDDIR
                     78: };
                     79:
                     80: static int flags = 0;
1.19      xsa        81: static char *date, *rev, *user, *tag;
1.9       joris      82: static char *zone = "+0000";
                     83: static u_int nbmod = 0;
                     84: static u_int rep = 0;
                     85: static char *modules[CVS_HISTORY_MAXMOD];
1.1       jfb        86:
1.14      jfb        87: static int
                     88: cvs_history_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        89: {
1.9       joris      90:        int ch;
1.1       jfb        91:
1.19      xsa        92:        date = rev = user = tag = NULL;
                     93:
1.14      jfb        94:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.1       jfb        95:                switch (ch) {
                     96:                case 'a':
                     97:                        flags |= CVS_HF_A;
                     98:                        break;
1.15      xsa        99:                case 'b':
                    100:                        break;
1.1       jfb       101:                case 'c':
                    102:                        rep++;
                    103:                        flags |= CVS_HF_C;
                    104:                        break;
1.15      xsa       105:                case 'D':
                    106:                        break;
1.1       jfb       107:                case 'e':
                    108:                        rep++;
                    109:                        flags |= CVS_HF_E;
                    110:                        break;
1.15      xsa       111:                case 'f':
                    112:                        break;
1.1       jfb       113:                case 'l':
                    114:                        flags |= CVS_HF_L;
                    115:                        break;
                    116:                case 'm':
                    117:                        rep++;
                    118:                        flags |= CVS_HF_M;
                    119:                        if (nbmod == CVS_HISTORY_MAXMOD) {
                    120:                                cvs_log(LP_ERR, "too many `-m' options");
1.13      joris     121:                                return (CVS_EX_USAGE);
1.1       jfb       122:                        }
                    123:                        modules[nbmod++] = optarg;
                    124:                        break;
1.15      xsa       125:                case 'n':
                    126:                        break;
1.1       jfb       127:                case 'o':
                    128:                        rep++;
                    129:                        flags |= CVS_HF_O;
                    130:                        break;
1.16      xsa       131:                case 'r':
                    132:                        rev = optarg;
                    133:                        break;
1.1       jfb       134:                case 'T':
                    135:                        rep++;
                    136:                        flags |= CVS_HF_T;
                    137:                        break;
                    138:                case 't':
                    139:                        tag = optarg;
                    140:                        break;
                    141:                case 'u':
                    142:                        user = optarg;
                    143:                        break;
                    144:                case 'w':
                    145:                        flags |= CVS_HF_W;
                    146:                        break;
                    147:                case 'x':
                    148:                        rep++;
                    149:                        break;
                    150:                case 'z':
                    151:                        zone = optarg;
                    152:                        break;
                    153:                default:
1.13      joris     154:                        return (CVS_EX_USAGE);
1.1       jfb       155:                }
                    156:        }
                    157:
                    158:        if (rep > 1) {
                    159:                cvs_log(LP_ERR,
                    160:                    "Only one report type allowed from: \"-Tcomxe\"");
1.13      joris     161:                return (CVS_EX_USAGE);
1.4       deraadt   162:        } else if (rep == 0)
1.1       jfb       163:                flags |= CVS_HF_O;    /* use -o as default */
                    164:
1.9       joris     165:        *arg = optind;
                    166:        return (0);
                    167: }
1.1       jfb       168:
1.14      jfb       169: static int
                    170: cvs_history_pre_exec(struct cvsroot *root)
1.9       joris     171: {
1.20      joris     172:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.24    ! joris     173:                if (flags & CVS_HF_A)
        !           174:                        cvs_sendarg(root, "-a", 0);
1.1       jfb       175:
1.24    ! joris     176:                if (flags & CVS_HF_C)
        !           177:                        cvs_sendarg(root, "-c", 0);
1.1       jfb       178:
1.24    ! joris     179:                if (flags & CVS_HF_O)
        !           180:                        cvs_sendarg(root, "-o", 0);
1.16      xsa       181:
1.24    ! joris     182:                if (date != NULL) {
        !           183:                        cvs_sendarg(root, "-D", 0);
        !           184:                        cvs_sendarg(root, date, 0);
        !           185:                }
        !           186:
        !           187:                if (rev != NULL) {
        !           188:                        cvs_sendarg(root, "-r", 0);
        !           189:                        cvs_sendarg(root, rev, 0);
        !           190:                }
        !           191:
        !           192:                if (tag != NULL) {
        !           193:                        cvs_sendarg(root, "-t", 0);
        !           194:                        cvs_sendarg(root, tag, 0);
        !           195:                }
1.1       jfb       196:
1.20      joris     197:                /* if no user is specified, get login name of command issuer */
                    198:                if (!(flags & CVS_HF_A) && (user == NULL)) {
1.24    ! joris     199:                        if ((user = getlogin()) == NULL)
        !           200:                                fatal("cannot get login name");
1.15      xsa       201:                }
1.20      joris     202:
                    203:                if (!(flags & CVS_HF_A)) {
1.24    ! joris     204:                        cvs_sendarg(root, "-u", 0);
        !           205:                        cvs_sendarg(root, user, 0);
1.20      joris     206:                }
                    207:
1.24    ! joris     208:                cvs_sendarg(root, "-z", 0);
        !           209:                cvs_sendarg(root, zone, 0);
1.15      xsa       210:        }
1.1       jfb       211:
                    212:        return (0);
                    213: }
                    214:
                    215:
1.21      joris     216: #if 0
1.1       jfb       217: static void
                    218: cvs_history_print(struct cvs_hent *hent)
                    219: {
                    220:        struct tm etime;
                    221:
                    222:        if (localtime_r(&(hent->ch_date), &etime) == NULL) {
1.17      xsa       223:                cvs_log(LP_ERR, "failed to convert timestamp to structure");
1.1       jfb       224:                return;
                    225:        }
                    226:
                    227:        printf("%c %4d-%02d-%02d %02d:%02d +%04d %-16s %-16s\n",
                    228:            hent->ch_event, etime.tm_year + 1900, etime.tm_mon + 1,
                    229:            etime.tm_mday, etime.tm_hour, etime.tm_min,
                    230:            0, hent->ch_user, hent->ch_repo);
                    231: }
1.21      joris     232: #endif