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

1.23    ! jfb         1: /*     $OpenBSD: getlog.c,v 1.22 2005/04/16 20:05:05 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:
                     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:
1.12      jfb       113:        ret = 0;
                    114:        root = CVS_DIR_ROOT(cf);
                    115:        repo = CVS_DIR_REPO(cf);
1.7       jfb       116:
1.13      jfb       117:        if (cf->cf_type == DT_DIR) {
1.20      jfb       118:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    119:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    120:                            CVS_FILE_NAME(cf));
                    121:                else
                    122:                        ret = cvs_senddir(root, cf);
1.12      jfb       123:                return (ret);
1.6       jfb       124:        }
                    125:
1.12      jfb       126:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.6       jfb       127:
1.23    ! jfb       128:        if (cvs_sendentry(root, cf) < 0) {
1.20      jfb       129:                return (-1);
                    130:        }
1.12      jfb       131:
1.20      jfb       132:        switch (cf->cf_cvstat) {
                    133:        case CVS_FST_UNKNOWN:
1.21      jfb       134:                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE, cf->cf_name);
1.20      jfb       135:                break;
                    136:        case CVS_FST_UPTODATE:
1.21      jfb       137:                ret = cvs_sendreq(root, CVS_REQ_UNCHANGED, cf->cf_name);
1.20      jfb       138:                break;
                    139:        case CVS_FST_ADDED:
                    140:        case CVS_FST_MODIFIED:
1.21      jfb       141:                ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED, cf->cf_name);
1.20      jfb       142:                break;
                    143:        default:
                    144:                break;
1.6       jfb       145:        }
1.5       jfb       146:
1.12      jfb       147:        return (ret);
1.6       jfb       148: }
1.5       jfb       149:
1.20      jfb       150:
                    151:
                    152: static int
                    153: cvs_getlog_local(CVSFILE *cf, void *arg)
1.1       jfb       154: {
1.22      xsa       155:        int nrev, l;
1.21      jfb       156:        char rcspath[MAXPATHLEN], numbuf[64];
1.20      jfb       157:        char *repo;
                    158:        RCSFILE *rf;
                    159:        struct rcs_sym *sym;
1.1       jfb       160:        struct rcs_delta *rdp;
1.21      jfb       161:        struct rcs_access *acp;
1.20      jfb       162:        struct cvsroot *root;
                    163:
                    164:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
1.21      jfb       165:                cvs_log(LP_WARN, "nothing known about %s", cf->cf_name);
1.20      jfb       166:                return (0);
                    167:        }
1.1       jfb       168:
1.21      jfb       169:        if (cf->cf_type == DT_DIR) {
                    170:                cvs_log(LP_INFO, "Logging %s", cf->cf_name);
1.20      jfb       171:                return (0);
1.21      jfb       172:        }
1.20      jfb       173:
                    174:        nrev = 0;
                    175:        root = CVS_DIR_ROOT(cf);
                    176:        repo = CVS_DIR_REPO(cf);
                    177:
1.22      xsa       178:        l = snprintf(rcspath, sizeof(rcspath), "%s/%s/%s%s",
1.20      jfb       179:            root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
1.22      xsa       180:        if (l == -1 || l >= (int)sizeof(rcspath)) {
                    181:                errno = ENAMETOOLONG;
                    182:                 cvs_log(LP_ERRNO, "%s", rcspath);
                    183:                return (-1);
                    184:        }
1.20      jfb       185:
1.21      jfb       186:        if (log_rfonly) {
                    187:                cvs_printf("%s\n", rcspath);
                    188:                return (0);
                    189:        }
                    190:
1.20      jfb       191:        rf = rcs_open(rcspath, RCS_READ);
                    192:        if (rf == NULL)
                    193:                return (-1);
                    194:
                    195:        cvs_printf("\nRCS file: %s\nWorking file: %s\n", rcspath, cf->cf_name);
                    196:        cvs_printf("head: %s\n",
                    197:            rcsnum_tostr(rcs_head_get(rf), numbuf, sizeof(numbuf)));
                    198:        cvs_printf("branch: %s\n",
                    199:            rcsnum_tostr(rcs_branch_get(rf), numbuf, sizeof(numbuf)));
1.21      jfb       200:        cvs_printf("locks: %s\n", (rf->rf_flags & RCS_SLOCK) ? "strict" : "");
1.20      jfb       201:
1.21      jfb       202:        cvs_printf("access list:\n");
                    203:        TAILQ_FOREACH(acp, &(rf->rf_access), ra_list)
                    204:                cvs_printf("\t%s\n", acp->ra_name);
                    205:
                    206:        if (!log_notags) {
                    207:                cvs_printf("symbolic names:\n");
                    208:                TAILQ_FOREACH(sym, &(rf->rf_symbols), rs_list)
                    209:                        cvs_printf("\t%s: %s\n", sym->rs_name,
                    210:                            rcsnum_tostr(sym->rs_num, numbuf, sizeof(numbuf)));
1.20      jfb       211:        }
1.21      jfb       212:
1.20      jfb       213:        cvs_printf("keyword substitution: %s\n", "");
1.1       jfb       214:
1.21      jfb       215:        if (log_honly)
                    216:                cvs_printf("total revisions: %u;\n", rf->rf_ndelta);
                    217:        else {
                    218:                cvs_printf("total revisions: %u;\tselected revisions: %u\n",
                    219:                    rf->rf_ndelta, nrev);
                    220:                cvs_printf("description:\n%s", rf->rf_desc);
                    221:                TAILQ_FOREACH(rdp, &(rf->rf_delta), rd_list) {
                    222:                        rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
                    223:                        cvs_printf(CVS_GETLOG_REVSEP "\nrevision %s\n", numbuf);
                    224:                        cvs_printf("date: %d/%02d/%02d %02d:%02d:%02d;"
                    225:                            "  author: %s;  state: %s;\n",
                    226:                            rdp->rd_date.tm_year + 1900,
                    227:                            rdp->rd_date.tm_mon + 1,
                    228:                            rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    229:                            rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    230:                            rdp->rd_author, rdp->rd_state);
                    231:                        cvs_printf("%s", rdp->rd_log);
                    232:                }
1.1       jfb       233:        }
                    234:
1.6       jfb       235:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.20      jfb       236:
                    237:        rcs_close(rf);
                    238:
                    239:        return (0);
1.1       jfb       240: }