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

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