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

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