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

Annotation of src/usr.bin/cvs/getlog.c, Revision 1.30

1.30    ! xsa         1: /*     $OpenBSD: getlog.c,v 1.29 2005/05/24 04:12:25 jfb Exp $ */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.10      tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.10      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.10      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.10      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.10      tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/param.h>
                     28:
                     29: #include <stdlib.h>
                     30: #include <stdio.h>
                     31: #include <unistd.h>
                     32: #include <errno.h>
                     33: #include <string.h>
                     34: #include <paths.h>
                     35:
                     36: #include "cvs.h"
                     37: #include "log.h"
1.6       jfb        38: #include "file.h"
1.3       jfb        39: #include "proto.h"
1.1       jfb        40:
                     41:
                     42: #define CVS_GLOG_RFONLY    0x01
                     43: #define CVS_GLOG_HDONLY    0x02
                     44:
                     45:
                     46: #define CVS_GETLOG_REVSEP   "----------------------------"
                     47: #define CVS_GETLOG_REVEND \
                     48:  "============================================================================="
                     49:
1.29      jfb        50: static int  cvs_getlog_remote  (CVSFILE *, void *);
                     51: static int  cvs_getlog_local   (CVSFILE *, void *);
                     52: static int cvs_getlog_options(struct cvs_cmd *, int, char **, int *);
1.25      xsa        53: static int cvs_getlog_sendflags(struct cvsroot *);
1.1       jfb        54:
1.29      jfb        55: struct cvs_cmd cvs_cmd_log = {
                     56:        CVS_OP_LOG, CVS_REQ_LOG, "log",
                     57:        { "lo" },
                     58:        "Print out history information for files",
                     59:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.30    ! xsa        60:        "bd:hlNRr:s:tw:",
1.29      jfb        61:        NULL,
                     62:        CF_RECURSE,
                     63:        cvs_getlog_options,
                     64:        NULL,
                     65:        cvs_getlog_remote,
                     66:        cvs_getlog_local,
                     67:        NULL,
                     68:        NULL,
                     69:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     70: };
                     71:
                     72:
                     73: struct cvs_cmd cvs_cmd_rlog = {
                     74:        CVS_OP_LOG, CVS_REQ_LOG, "log",
                     75:        { "lo" },
                     76:        "Print out history information for files",
                     77:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
                     78:        "d:hlRr:",
                     79:        NULL,
                     80:        CF_RECURSE,
1.16      joris      81:        cvs_getlog_options,
1.25      xsa        82:        cvs_getlog_sendflags,
1.21      jfb        83:        cvs_getlog_remote,
1.29      jfb        84:        cvs_getlog_local,
                     85:        NULL,
                     86:        NULL,
1.16      joris      87:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     88: };
                     89:
1.21      jfb        90: static int log_rfonly = 0;
                     91: static int log_honly = 0;
1.25      xsa        92: static int log_lhonly = 0;
1.21      jfb        93: static int log_notags = 0;
1.1       jfb        94:
1.25      xsa        95: static int
1.29      jfb        96: cvs_getlog_options(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        97: {
1.16      joris      98:        int ch;
1.1       jfb        99:
1.29      jfb       100:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.16      joris     101:                switch (ch) {
1.25      xsa       102:                case 'b':
                    103:                        break;
1.1       jfb       104:                case 'd':
                    105:                        break;
                    106:                case 'h':
1.21      jfb       107:                        log_honly = 1;
1.1       jfb       108:                        break;
                    109:                case 'l':
1.29      jfb       110:                        cmd->file_flags &= ~CF_RECURSE;
1.1       jfb       111:                        break;
1.21      jfb       112:                case 'N':
                    113:                        log_notags = 1;
                    114:                        break;
1.1       jfb       115:                case 'R':
1.21      jfb       116:                        log_rfonly = 1;
1.1       jfb       117:                        break;
                    118:                case 'r':
                    119:                        break;
1.25      xsa       120:                case 's':
                    121:                        break;
                    122:                case 't':
                    123:                        log_lhonly = 1;
                    124:                        break;
                    125:                case 'w':
                    126:                        break;
1.1       jfb       127:                default:
1.19      joris     128:                        return (CVS_EX_USAGE);
1.1       jfb       129:                }
                    130:        }
                    131:
1.16      joris     132:        *arg = optind;
1.1       jfb       133:        return (0);
                    134: }
                    135:
1.25      xsa       136: static int
                    137: cvs_getlog_sendflags(struct cvsroot *root)
                    138: {
                    139:        if (log_honly && (cvs_sendarg(root, "-h", 0) < 0))
                    140:                return (CVS_EX_PROTO);
                    141:        if (log_notags && (cvs_sendarg(root, "-N", 0) < 0))
                    142:                return (CVS_EX_PROTO);
                    143:        if (log_rfonly && (cvs_sendarg(root, "-R", 0) < 0))
                    144:                return (CVS_EX_PROTO);
                    145:        if (log_lhonly && (cvs_sendarg(root, "-t", 0) < 0))
                    146:                return (CVS_EX_PROTO);
                    147:
                    148:        return (0);
                    149: }
1.1       jfb       150:
1.6       jfb       151: /*
1.21      jfb       152:  * cvs_getlog_remote()
1.6       jfb       153:  *
                    154:  */
                    155: static int
1.21      jfb       156: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6       jfb       157: {
1.12      jfb       158:        int ret;
1.7       jfb       159:        char *repo, fpath[MAXPATHLEN];
1.6       jfb       160:        struct cvsroot *root;
                    161:
1.12      jfb       162:        ret = 0;
                    163:        root = CVS_DIR_ROOT(cf);
                    164:        repo = CVS_DIR_REPO(cf);
1.7       jfb       165:
1.13      jfb       166:        if (cf->cf_type == DT_DIR) {
1.20      jfb       167:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    168:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    169:                            CVS_FILE_NAME(cf));
                    170:                else
                    171:                        ret = cvs_senddir(root, cf);
1.12      jfb       172:                return (ret);
1.6       jfb       173:        }
                    174:
1.12      jfb       175:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6       jfb       176:
1.27      jfb       177:        if (cvs_sendentry(root, cf) < 0)
                    178:                return (CVS_EX_PROTO);
1.12      jfb       179:
1.20      jfb       180:        switch (cf->cf_cvstat) {
                    181:        case CVS_FST_UNKNOWN:
1.21      jfb       182:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20      jfb       183:                break;
                    184:        case CVS_FST_UPTODATE:
1.21      jfb       185:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20      jfb       186:                break;
                    187:        case CVS_FST_ADDED:
                    188:        case CVS_FST_MODIFIED:
1.21      jfb       189:                ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20      jfb       190:                break;
                    191:        default:
                    192:                break;
1.6       jfb       193:        }
1.5       jfb       194:
1.27      jfb       195:        if (ret == -1)
                    196:                ret = CVS_EX_PROTO;
1.12      jfb       197:        return (ret);
1.6       jfb       198: }
1.5       jfb       199:
1.20      jfb       200:
                    201:
                    202: static int
                    203: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1       jfb       204: {
1.22      xsa       205:        int nrev, l;
1.21      jfb       206:        char rcspath[MAXPATHLEN], numbuf[64];
1.20      jfb       207:        char *repo;
                    208:        RCSFILE *rf;
                    209:        struct rcs_sym *sym;
1.1       jfb       210:        struct rcs_delta *rdp;
1.21      jfb       211:        struct rcs_access *acp;
1.20      jfb       212:        struct cvsroot *root;
                    213:
                    214:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.21      jfb       215:                cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20      jfb       216:                return (0);
                    217:        }
1.1       jfb       218:
1.21      jfb       219:        if (cf->cf_type == DT_DIR) {
                    220:                cvs_log(LP_INFO, "Logging %s", cf->cf_name);
1.20      jfb       221:                return (0);
1.21      jfb       222:        }
1.20      jfb       223:
                    224:        nrev = 0;
                    225:        root = CVS_DIR_ROOT(cf);
                    226:        repo = CVS_DIR_REPO(cf);
                    227:
1.22      xsa       228:        l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.20      jfb       229:            root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
1.22      xsa       230:        if (l == -1 || l >= (int)sizeof(rcspath)) {
                    231:                errno = ENAMETOOLONG;
                    232:                 cvs_log(LP_ERRNO, "%s", rcspath);
1.28      joris     233:                return (CVS_EX_DATA);
1.22      xsa       234:        }
1.20      jfb       235:
1.21      jfb       236:        if (log_rfonly) {
                    237:                cvs_printf("%s\n", rcspath);
                    238:                return (0);
                    239:        }
                    240:
1.20      jfb       241:        rf = rcs_open(rcspath, RCS_READ);
                    242:        if (rf == NULL)
1.28      joris     243:                return (CVS_EX_DATA);
1.20      jfb       244:
                    245:        cvs_printf("\nRCS file: %s\nWorking file: %s\n", rcspath, cf->cf_name);
                    246:        cvs_printf("head: %s\n",
                    247:            rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
                    248:        cvs_printf("branch: %s\n",
                    249:            rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
1.21      jfb       250:        cvs_printf("locks: %s\n", (rf->rf_flags & RCS_SLOCK) ? "strict" : "");
1.20      jfb       251:
1.21      jfb       252:        cvs_printf("access list:\n");
                    253:        TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
                    254:                cvs_printf("\t%s\n", acp->ra_name);
                    255:
                    256:        if (!log_notags) {
                    257:                cvs_printf("symbolic names:\n");
                    258:                TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
                    259:                        cvs_printf("\t%s: %s\n", sym->rs_name,
                    260:                            rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20      jfb       261:        }
1.21      jfb       262:
1.20      jfb       263:        cvs_printf("keyword substitution: %s\n", "");
1.1       jfb       264:
1.21      jfb       265:        if (log_honly)
                    266:                cvs_printf("total revisions: %u;\n", rf->rf_ndelta);
                    267:        else {
                    268:                cvs_printf("total revisions: %u;\tselected revisions: %u\n",
                    269:                    rf->rf_ndelta, nrev);
1.26      xsa       270:
                    271:                if (log_lhonly)
                    272:                        cvs_printf("description:\n%s", rf->rf_desc);
                    273:
1.21      jfb       274:                TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
                    275:                        rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
                    276:                        cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
                    277:                        cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
                    278:                            "  author: %s;  state: %s;\n",
                    279:                            rdp->rd_date.tm_year + 1900,
                    280:                            rdp->rd_date.tm_mon + 1,
                    281:                            rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    282:                            rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    283:                            rdp->rd_author, rdp->rd_state);
                    284:                        cvs_printf("%s", rdp->rd_log);
                    285:                }
1.1       jfb       286:        }
                    287:
1.6       jfb       288:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.20      jfb       289:
                    290:        rcs_close(rf);
                    291:
                    292:        return (0);
1.1       jfb       293: }