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

1.40    ! joris       1: /*     $OpenBSD: getlog.c,v 1.39 2005/07/15 08:39:14 xsa 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:
1.31      xsa        29: #include <errno.h>
                     30: #include <paths.h>
                     31: #include <stdio.h>
1.1       jfb        32: #include <stdlib.h>
1.31      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:
                     40:
                     41: #define CVS_GLOG_RFONLY    0x01
                     42: #define CVS_GLOG_HDONLY    0x02
                     43:
                     44:
                     45: #define CVS_GETLOG_REVSEP   "----------------------------"
                     46: #define CVS_GETLOG_REVEND \
                     47:  "============================================================================="
                     48:
1.33      xsa        49: static int cvs_getlog_init     (struct cvs_cmd *, int, char **, int *);
                     50: static int cvs_getlog_remote   (CVSFILE *, void *);
                     51: static int cvs_getlog_local    (CVSFILE *, void *);
                     52: static int cvs_getlog_pre_exec (struct cvsroot *);
1.1       jfb        53:
1.29      jfb        54: struct cvs_cmd cvs_cmd_log = {
                     55:        CVS_OP_LOG, CVS_REQ_LOG, "log",
                     56:        { "lo" },
                     57:        "Print out history information for files",
                     58:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.30      xsa        59:        "bd:hlNRr:s:tw:",
1.29      jfb        60:        NULL,
1.40    ! joris      61:        CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33      xsa        62:        cvs_getlog_init,
                     63:        cvs_getlog_pre_exec,
1.29      jfb        64:        cvs_getlog_remote,
                     65:        cvs_getlog_local,
                     66:        NULL,
                     67:        NULL,
                     68:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     69: };
                     70:
                     71:
                     72: struct cvs_cmd cvs_cmd_rlog = {
                     73:        CVS_OP_LOG, CVS_REQ_LOG, "log",
                     74:        { "lo" },
                     75:        "Print out history information for files",
                     76:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
                     77:        "d:hlRr:",
                     78:        NULL,
1.40    ! joris      79:        CF_NOSYMS | CF_IGNORE | CF_SORT | CF_RECURSE,
1.33      xsa        80:        cvs_getlog_init,
                     81:        cvs_getlog_pre_exec,
1.21      jfb        82:        cvs_getlog_remote,
1.29      jfb        83:        cvs_getlog_local,
                     84:        NULL,
                     85:        NULL,
1.16      joris      86:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     87: };
                     88:
1.21      jfb        89: static int log_rfonly = 0;
                     90: static int log_honly = 0;
1.25      xsa        91: static int log_lhonly = 0;
1.21      jfb        92: static int log_notags = 0;
1.1       jfb        93:
1.25      xsa        94: static int
1.33      xsa        95: cvs_getlog_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
1.1       jfb        96: {
1.16      joris      97:        int ch;
1.1       jfb        98:
1.29      jfb        99:        while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
1.16      joris     100:                switch (ch) {
1.25      xsa       101:                case 'b':
                    102:                        break;
1.1       jfb       103:                case 'd':
                    104:                        break;
                    105:                case 'h':
1.21      jfb       106:                        log_honly = 1;
1.1       jfb       107:                        break;
                    108:                case 'l':
1.29      jfb       109:                        cmd->file_flags &= ~CF_RECURSE;
1.1       jfb       110:                        break;
1.21      jfb       111:                case 'N':
                    112:                        log_notags = 1;
                    113:                        break;
1.1       jfb       114:                case 'R':
1.21      jfb       115:                        log_rfonly = 1;
1.1       jfb       116:                        break;
                    117:                case 'r':
                    118:                        break;
1.25      xsa       119:                case 's':
                    120:                        break;
                    121:                case 't':
                    122:                        log_lhonly = 1;
                    123:                        break;
                    124:                case 'w':
                    125:                        break;
1.1       jfb       126:                default:
1.19      joris     127:                        return (CVS_EX_USAGE);
1.1       jfb       128:                }
                    129:        }
                    130:
1.16      joris     131:        *arg = optind;
1.1       jfb       132:        return (0);
                    133: }
                    134:
1.25      xsa       135: static int
1.33      xsa       136: cvs_getlog_pre_exec(struct cvsroot *root)
1.25      xsa       137: {
1.33      xsa       138:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    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:        }
1.25      xsa       148:
                    149:        return (0);
                    150: }
1.1       jfb       151:
1.6       jfb       152: /*
1.21      jfb       153:  * cvs_getlog_remote()
1.6       jfb       154:  *
                    155:  */
                    156: static int
1.21      jfb       157: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6       jfb       158: {
1.12      jfb       159:        int ret;
1.7       jfb       160:        char *repo, fpath[MAXPATHLEN];
1.6       jfb       161:        struct cvsroot *root;
                    162:
1.12      jfb       163:        ret = 0;
                    164:        root = CVS_DIR_ROOT(cf);
                    165:        repo = CVS_DIR_REPO(cf);
1.7       jfb       166:
1.13      jfb       167:        if (cf->cf_type == DT_DIR) {
1.20      jfb       168:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    169:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    170:                            CVS_FILE_NAME(cf));
                    171:                else
                    172:                        ret = cvs_senddir(root, cf);
1.12      jfb       173:                return (ret);
1.6       jfb       174:        }
                    175:
1.12      jfb       176:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6       jfb       177:
1.27      jfb       178:        if (cvs_sendentry(root, cf) < 0)
                    179:                return (CVS_EX_PROTO);
1.12      jfb       180:
1.20      jfb       181:        switch (cf->cf_cvstat) {
                    182:        case CVS_FST_UNKNOWN:
1.21      jfb       183:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20      jfb       184:                break;
                    185:        case CVS_FST_UPTODATE:
1.21      jfb       186:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20      jfb       187:                break;
                    188:        case CVS_FST_ADDED:
                    189:        case CVS_FST_MODIFIED:
1.21      jfb       190:                ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20      jfb       191:                break;
                    192:        default:
                    193:                break;
1.6       jfb       194:        }
1.5       jfb       195:
1.27      jfb       196:        if (ret == -1)
                    197:                ret = CVS_EX_PROTO;
1.12      jfb       198:        return (ret);
1.6       jfb       199: }
1.5       jfb       200:
1.20      jfb       201:
                    202:
                    203: static int
                    204: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1       jfb       205: {
1.38      xsa       206:        int nrev;
1.21      jfb       207:        char rcspath[MAXPATHLEN], numbuf[64];
1.20      jfb       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:
1.39      xsa       213:        nrev = 0;
                    214:
                    215:        if (cf->cf_cvstat == CVS_FST_ADDED) {
                    216:                if (verbosity > 0)
                    217:                        cvs_log(LP_WARN, "%s has been added, but not committed",
                    218:                            cf->cf_name);
                    219:                return (0);
                    220:        }
                    221:
1.20      jfb       222:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.37      xsa       223:                if (verbosity > 0)
                    224:                        cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20      jfb       225:                return (0);
                    226:        }
1.1       jfb       227:
1.21      jfb       228:        if (cf->cf_type == DT_DIR) {
1.36      xsa       229:                if (verbosity > 1)
                    230:                        cvs_log(LP_INFO, "Logging %s", cf->cf_name);
1.20      jfb       231:                return (0);
1.21      jfb       232:        }
1.20      jfb       233:
1.38      xsa       234:        if (cvs_rcs_getpath(cf, rcspath, sizeof(rcspath)) == NULL)
1.28      joris     235:                return (CVS_EX_DATA);
1.20      jfb       236:
1.21      jfb       237:        if (log_rfonly) {
                    238:                cvs_printf("%s\n", rcspath);
                    239:                return (0);
                    240:        }
                    241:
1.20      jfb       242:        rf = rcs_open(rcspath, RCS_READ);
                    243:        if (rf == NULL)
1.28      joris     244:                return (CVS_EX_DATA);
1.20      jfb       245:
1.32      xsa       246:        cvs_printf("\nRCS file: %s", rcspath);
                    247:        cvs_printf("\nWorking file: %s", cf->cf_name);
                    248:        cvs_printf("\nhead:");
                    249:        if (rcs_head_get(rf) != NULL) {
                    250:                cvs_printf(" %s",
                    251:                    rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
                    252:        }
                    253:        cvs_printf("\nbranch:");
                    254:        if (rcs_branch_get(rf) != NULL) {
                    255:                cvs_printf(" %s",
                    256:                    rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
                    257:        }
                    258:        cvs_printf("\nlocks:%s", (rf->rf_flags & RCS_SLOCK) ? " strict" : "");
1.20      jfb       259:
1.32      xsa       260:        cvs_printf("\naccess list:\n");
1.21      jfb       261:        TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
                    262:                cvs_printf("\t%s\n", acp->ra_name);
                    263:
                    264:        if (!log_notags) {
                    265:                cvs_printf("symbolic names:\n");
                    266:                TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
                    267:                        cvs_printf("\t%s: %s\n", sym->rs_name,
                    268:                            rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20      jfb       269:        }
1.21      jfb       270:
1.32      xsa       271:        cvs_printf("keyword substitution: %s\n",
                    272:            rf->rf_expand == NULL ? "kv" : rf->rf_expand);
1.1       jfb       273:
1.33      xsa       274:        cvs_printf("total revisions: %u;", rf->rf_ndelta);
                    275:
1.34      xsa       276:        if (!log_honly && !log_lhonly)
1.33      xsa       277:                cvs_printf("\tselected revisions: %u", nrev);
1.35      joris     278:
1.33      xsa       279:        cvs_printf("\n");
1.26      xsa       280:
1.33      xsa       281:        if (!log_honly || log_lhonly)
                    282:                cvs_printf("description:\n%s", rf->rf_desc);
1.26      xsa       283:
1.33      xsa       284:        if (!log_honly && !log_lhonly) {
1.21      jfb       285:                TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
                    286:                        rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
                    287:                        cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
                    288:                        cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
1.35      joris     289:                            "  author: %s;  state: %s;\n",
1.21      jfb       290:                            rdp->rd_date.tm_year + 1900,
                    291:                            rdp->rd_date.tm_mon + 1,
                    292:                            rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    293:                            rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    294:                            rdp->rd_author, rdp->rd_state);
                    295:                        cvs_printf("%s", rdp->rd_log);
                    296:                }
1.1       jfb       297:        }
                    298:
1.6       jfb       299:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.20      jfb       300:
                    301:        rcs_close(rf);
                    302:
                    303:        return (0);
1.1       jfb       304: }