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

1.10    ! xsa         1: /*     $OpenBSD: history.c,v 1.9 2005/03/30 17:43:04 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:
                     27: #include <sys/param.h>
                     28: #include <sys/stat.h>
                     29:
                     30: #include <errno.h>
                     31: #include <stdio.h>
                     32: #include <fcntl.h>
                     33: #include <stdlib.h>
                     34: #include <unistd.h>
                     35: #include <string.h>
                     36: #include <sysexits.h>
                     37:
                     38: #include "cvs.h"
                     39: #include "rcs.h"
                     40: #include "log.h"
1.3       jfb        41: #include "proto.h"
1.1       jfb        42:
                     43: #define CVS_HISTORY_MAXMOD    16
                     44:
                     45: /* history flags */
                     46: #define CVS_HF_A     0x01
                     47: #define CVS_HF_C     0x02
                     48: #define CVS_HF_E     0x04
                     49: #define CVS_HF_L     0x08
                     50: #define CVS_HF_M     0x10
                     51: #define CVS_HF_O     0x20
                     52: #define CVS_HF_T     0x40
                     53: #define CVS_HF_W     0x80
                     54:
                     55: #define CVS_HF_EXCL (CVS_HF_C|CVS_HF_E|CVS_HF_M|CVS_HF_O|CVS_HF_T|CVS_HF_X)
                     56:
                     57: static void  cvs_history_print  (struct cvs_hent *);
1.9       joris      58: int cvs_history_options(char *, int, char **, int *);
                     59: int cvs_history_sendflags(struct cvsroot *);
1.1       jfb        60:
                     61: extern char *__progname;
                     62:
1.9       joris      63: struct cvs_cmd_info cvs_history = {
                     64:        cvs_history_options,
                     65:        cvs_history_sendflags,
                     66:        NULL,
                     67:        NULL,
                     68:        NULL,
                     69:        0,
                     70:        CVS_REQ_HISTORY,
                     71:        CVS_CMD_SENDDIR
                     72: };
                     73:
                     74: static int flags = 0;
                     75: static char *user = NULL;
                     76: static char *zone = "+0000";
                     77: static char *tag = NULL;
                     78: static u_int nbmod = 0;
                     79: static u_int rep = 0;
                     80: static char *modules[CVS_HISTORY_MAXMOD];
1.1       jfb        81:
                     82: int
1.9       joris      83: cvs_history_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        84: {
1.9       joris      85:        int ch;
1.1       jfb        86:
1.9       joris      87:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        88:                switch (ch) {
                     89:                case 'a':
                     90:                        flags |= CVS_HF_A;
                     91:                        break;
                     92:                case 'c':
                     93:                        rep++;
                     94:                        flags |= CVS_HF_C;
                     95:                        break;
                     96:                case 'e':
                     97:                        rep++;
                     98:                        flags |= CVS_HF_E;
                     99:                        break;
                    100:                case 'l':
                    101:                        flags |= CVS_HF_L;
                    102:                        break;
                    103:                case 'm':
                    104:                        rep++;
                    105:                        flags |= CVS_HF_M;
                    106:                        if (nbmod == CVS_HISTORY_MAXMOD) {
                    107:                                cvs_log(LP_ERR, "too many `-m' options");
                    108:                                return (EX_USAGE);
                    109:                        }
                    110:                        modules[nbmod++] = optarg;
                    111:                        break;
                    112:                case 'o':
                    113:                        rep++;
                    114:                        flags |= CVS_HF_O;
                    115:                        break;
                    116:                case 'T':
                    117:                        rep++;
                    118:                        flags |= CVS_HF_T;
                    119:                        break;
                    120:                case 't':
                    121:                        tag = optarg;
                    122:                        break;
                    123:                case 'u':
                    124:                        user = optarg;
                    125:                        break;
                    126:                case 'w':
                    127:                        flags |= CVS_HF_W;
                    128:                        break;
                    129:                case 'x':
                    130:                        rep++;
                    131:                        break;
                    132:                case 'z':
                    133:                        zone = optarg;
                    134:                        break;
                    135:                default:
                    136:                        return (EX_USAGE);
                    137:                }
                    138:        }
                    139:
                    140:        if (rep > 1) {
                    141:                cvs_log(LP_ERR,
                    142:                    "Only one report type allowed from: \"-Tcomxe\"");
                    143:                return (EX_USAGE);
1.4       deraadt   144:        } else if (rep == 0)
1.1       jfb       145:                flags |= CVS_HF_O;    /* use -o as default */
                    146:
1.9       joris     147:        *arg = optind;
                    148:        return (0);
                    149: }
1.1       jfb       150:
1.9       joris     151: int
                    152: cvs_history_sendflags(struct cvsroot *root)
                    153: {
1.1       jfb       154:
1.9       joris     155:        if ((flags & CVS_HF_C) && (cvs_sendarg(root, "-c", 0) < 0))
1.10    ! xsa       156:                return (-1);
1.1       jfb       157:
1.9       joris     158:        if ((flags & CVS_HF_O) && (cvs_sendarg(root, "-o", 0) < 0))
1.10    ! xsa       159:                return (-1);
1.1       jfb       160:
1.9       joris     161:        if (tag != NULL) {
                    162:                if ((cvs_sendarg(root, "-t", 0) < 0) ||
                    163:                    (cvs_sendarg(root, tag, 0) < 0))
1.10    ! xsa       164:                        return (-1);
1.9       joris     165:        }
1.1       jfb       166:
1.9       joris     167:        if (user != NULL) {
                    168:                if ((cvs_sendarg(root, "-u", 0) < 0) ||
                    169:                    (cvs_sendarg(root, user, 0) < 0))
1.10    ! xsa       170:                        return (-1);
1.1       jfb       171:        }
1.9       joris     172:
                    173:        if ((cvs_sendarg(root, "-z", 0) < 0) ||
                    174:            (cvs_sendarg(root, zone, 0) < 0))
1.10    ! xsa       175:                return (-1);
1.1       jfb       176:
                    177:        return (0);
                    178: }
                    179:
                    180:
                    181: static void
                    182: cvs_history_print(struct cvs_hent *hent)
                    183: {
                    184:        struct tm etime;
                    185:
                    186:        if (localtime_r(&(hent->ch_date), &etime) == NULL) {
                    187:                cvs_log(LP_ERROR, "failed to convert timestamp to structure");
                    188:                return;
                    189:        }
                    190:
                    191:        printf("%c %4d-%02d-%02d %02d:%02d +%04d %-16s %-16s\n",
                    192:            hent->ch_event, etime.tm_year + 1900, etime.tm_mon + 1,
                    193:            etime.tm_mday, etime.tm_hour, etime.tm_min,
                    194:            0, hent->ch_user, hent->ch_repo);
                    195: }