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

1.22    ! xsa         1: /*     $OpenBSD: getlog.c,v 1.21 2005/04/13 19:44:42 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.21      jfb        50: static int  cvs_getlog_remote  (CVSFILE *, void *);
1.20      jfb        51: static int  cvs_getlog_local   (CVSFILE *, void *);
1.1       jfb        52:
1.16      joris      53: int cvs_getlog_options(char *, int, char **, int *);
1.1       jfb        54:
1.16      joris      55: struct cvs_cmd_info cvs_getlog = {
                     56:        cvs_getlog_options,
                     57:        NULL,
1.21      jfb        58:        cvs_getlog_remote,
1.16      joris      59:        NULL, NULL,
                     60:        CF_RECURSE,
                     61:        CVS_REQ_LOG,
                     62:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     63: };
                     64:
1.21      jfb        65: static int log_rfonly = 0;
                     66: static int log_honly = 0;
                     67: static int log_notags = 0;
1.1       jfb        68:
                     69: int
1.16      joris      70: cvs_getlog_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        71: {
1.16      joris      72:        int ch;
1.1       jfb        73:
1.16      joris      74:        while ((ch = getopt(argc, argv, opt)) != -1) {
                     75:                switch (ch) {
1.1       jfb        76:                case 'd':
                     77:                        break;
                     78:                case 'h':
1.21      jfb        79:                        log_honly = 1;
1.1       jfb        80:                        break;
                     81:                case 'l':
1.16      joris      82:                        cvs_getlog.file_flags &= ~CF_RECURSE;
1.1       jfb        83:                        break;
1.21      jfb        84:                case 'N':
                     85:                        log_notags = 1;
                     86:                        break;
1.1       jfb        87:                case 'R':
1.21      jfb        88:                        log_rfonly = 1;
1.1       jfb        89:                        break;
                     90:                case 'r':
                     91:                        break;
                     92:                default:
1.19      joris      93:                        return (CVS_EX_USAGE);
1.1       jfb        94:                }
                     95:        }
                     96:
1.16      joris      97:        *arg = optind;
1.1       jfb        98:        return (0);
                     99: }
                    100:
                    101:
1.6       jfb       102: /*
1.21      jfb       103:  * cvs_getlog_remote()
1.6       jfb       104:  *
                    105:  */
                    106: static int
1.21      jfb       107: cvs_getlog_remote(CVSFILE *cf, void *arg)
1.6       jfb       108: {
1.12      jfb       109:        int ret;
1.7       jfb       110:        char *repo, fpath[MAXPATHLEN];
1.6       jfb       111:        struct cvsroot *root;
                    112:        struct cvs_ent *entp;
                    113:
1.12      jfb       114:        ret = 0;
                    115:        root = CVS_DIR_ROOT(cf);
                    116:        repo = CVS_DIR_REPO(cf);
1.7       jfb       117:
1.13      jfb       118:        if (cf->cf_type == DT_DIR) {
1.20      jfb       119:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    120:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    121:                            CVS_FILE_NAME(cf));
                    122:                else
                    123:                        ret = cvs_senddir(root, cf);
1.12      jfb       124:                return (ret);
1.6       jfb       125:        }
                    126:
1.12      jfb       127:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.7       jfb       128:        entp = cvs_ent_getent(fpath);
1.6       jfb       129:
1.20      jfb       130:        if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
                    131:                cvs_ent_free(entp);
                    132:                return (-1);
                    133:        }
1.12      jfb       134:
1.20      jfb       135:        switch (cf->cf_cvstat) {
                    136:        case CVS_FST_UNKNOWN:
1.21      jfb       137:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20      jfb       138:                break;
                    139:        case CVS_FST_UPTODATE:
1.21      jfb       140:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20      jfb       141:                break;
                    142:        case CVS_FST_ADDED:
                    143:        case CVS_FST_MODIFIED:
1.21      jfb       144:                ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20      jfb       145:                break;
                    146:        default:
                    147:                break;
1.6       jfb       148:        }
1.5       jfb       149:
1.12      jfb       150:        if (entp != NULL)
1.6       jfb       151:                cvs_ent_free(entp);
1.12      jfb       152:        return (ret);
1.6       jfb       153: }
1.5       jfb       154:
1.20      jfb       155:
                    156:
                    157: static int
                    158: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1       jfb       159: {
1.22    ! xsa       160:        int nrev, l;
1.21      jfb       161:        char rcspath[MAXPATHLEN], numbuf[64];
1.20      jfb       162:        char *repo;
                    163:        RCSFILE *rf;
                    164:        struct rcs_sym *sym;
1.1       jfb       165:        struct rcs_delta *rdp;
1.21      jfb       166:        struct rcs_access *acp;
1.20      jfb       167:        struct cvsroot *root;
                    168:
                    169:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.21      jfb       170:                cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20      jfb       171:                return (0);
                    172:        }
1.1       jfb       173:
1.21      jfb       174:        if (cf->cf_type == DT_DIR) {
                    175:                cvs_log(LP_INFO, "Logging %s", cf->cf_name);
1.20      jfb       176:                return (0);
1.21      jfb       177:        }
1.20      jfb       178:
                    179:        nrev = 0;
                    180:        root = CVS_DIR_ROOT(cf);
                    181:        repo = CVS_DIR_REPO(cf);
                    182:
1.22    ! xsa       183:        l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.20      jfb       184:            root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
1.22    ! xsa       185:        if (l == -1 || l >= (int)sizeof(rcspath)) {
        !           186:                errno = ENAMETOOLONG;
        !           187:                 cvs_log(LP_ERRNO, "%s", rcspath);
        !           188:                return (-1);
        !           189:        }
1.20      jfb       190:
1.21      jfb       191:        if (log_rfonly) {
                    192:                cvs_printf("%s\n", rcspath);
                    193:                return (0);
                    194:        }
                    195:
1.20      jfb       196:        rf = rcs_open(rcspath, RCS_READ);
                    197:        if (rf == NULL)
                    198:                return (-1);
                    199:
                    200:        cvs_printf("\nRCS file: %s\nWorking file: %s\n", rcspath, cf->cf_name);
                    201:        cvs_printf("head: %s\n",
                    202:            rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
                    203:        cvs_printf("branch: %s\n",
                    204:            rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
1.21      jfb       205:        cvs_printf("locks: %s\n", (rf->rf_flags & RCS_SLOCK) ? "strict" : "");
1.20      jfb       206:
1.21      jfb       207:        cvs_printf("access list:\n");
                    208:        TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
                    209:                cvs_printf("\t%s\n", acp->ra_name);
                    210:
                    211:        if (!log_notags) {
                    212:                cvs_printf("symbolic names:\n");
                    213:                TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
                    214:                        cvs_printf("\t%s: %s\n", sym->rs_name,
                    215:                            rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20      jfb       216:        }
1.21      jfb       217:
1.20      jfb       218:        cvs_printf("keyword substitution: %s\n", "");
1.1       jfb       219:
1.21      jfb       220:        if (log_honly)
                    221:                cvs_printf("total revisions: %u;\n", rf->rf_ndelta);
                    222:        else {
                    223:                cvs_printf("total revisions: %u;\tselected revisions: %u\n",
                    224:                    rf->rf_ndelta, nrev);
                    225:                cvs_printf("description:\n%s", rf->rf_desc);
                    226:                TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
                    227:                        rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
                    228:                        cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
                    229:                        cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
                    230:                            "  author: %s;  state: %s;\n",
                    231:                            rdp->rd_date.tm_year + 1900,
                    232:                            rdp->rd_date.tm_mon + 1,
                    233:                            rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    234:                            rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    235:                            rdp->rd_author, rdp->rd_state);
                    236:                        cvs_printf("%s", rdp->rd_log);
                    237:                }
1.1       jfb       238:        }
                    239:
1.6       jfb       240:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.20      jfb       241:
                    242:        rcs_close(rf);
                    243:
                    244:        return (0);
1.1       jfb       245: }