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

1.10    ! tedu        1: /*     $OpenBSD: getlog.c,v 1.9 2004/12/06 21:03:12 deraadt 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: #include <sysexits.h>
                     36:
                     37: #include "cvs.h"
                     38: #include "log.h"
1.6       jfb        39: #include "file.h"
1.3       jfb        40: #include "proto.h"
1.1       jfb        41:
                     42:
                     43: #define CVS_GLOG_RFONLY    0x01
                     44: #define CVS_GLOG_HDONLY    0x02
                     45:
                     46:
                     47: #define CVS_GETLOG_REVSEP   "----------------------------"
                     48: #define CVS_GETLOG_REVEND \
                     49:  "============================================================================="
                     50:
1.10    ! tedu       51: #ifdef notyet
1.1       jfb        52: static void cvs_getlog_print   (const char *, RCSFILE *, u_int);
1.8       jfb        53: #endif
1.6       jfb        54: static int  cvs_getlog_file    (CVSFILE *, void *);
1.1       jfb        55:
                     56:
                     57:
                     58: /*
                     59:  * cvs_getlog()
                     60:  *
                     61:  * Implement the `cvs log' command.
                     62:  */
                     63: int
                     64: cvs_getlog(int argc, char **argv)
                     65: {
1.5       jfb        66:        int i, rfonly, honly, flags;
1.6       jfb        67:        struct cvsroot *root;
1.1       jfb        68:
1.5       jfb        69:        flags = CF_RECURSE;
1.1       jfb        70:        rfonly = 0;
                     71:        honly = 0;
                     72:
                     73:        while ((i = getopt(argc, argv, "d:hlRr:")) != -1) {
                     74:                switch (i) {
                     75:                case 'd':
                     76:                        break;
                     77:                case 'h':
                     78:                        honly = 1;
                     79:                        break;
                     80:                case 'l':
1.5       jfb        81:                        flags &= ~CF_RECURSE;
1.1       jfb        82:                        break;
                     83:                case 'R':
                     84:                        rfonly = 1;
                     85:                        break;
                     86:                case 'r':
                     87:                        break;
                     88:                default:
                     89:                        return (EX_USAGE);
                     90:                }
                     91:        }
                     92:
                     93:        argc -= optind;
                     94:        argv += optind;
                     95:
1.4       jfb        96:        if (argc == 0) {
1.5       jfb        97:                cvs_files = cvs_file_get(".", flags);
1.9       deraadt    98:        } else {
1.5       jfb        99:                cvs_files = cvs_file_getspec(argv, argc, flags);
1.1       jfb       100:        }
1.5       jfb       101:        if (cvs_files == NULL)
                    102:                return (EX_DATAERR);
1.1       jfb       103:
1.6       jfb       104:        cvs_file_examine(cvs_files, cvs_getlog_file, NULL);
                    105:
                    106:        root = cvs_files->cf_ddat->cd_root;
                    107:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    108:                cvs_senddir(root, cvs_files);
                    109:                if (argc > 0) {
                    110:                        for (i = 0; i < argc; i++)
                    111:                                cvs_sendarg(root, argv[i], 0);
                    112:                }
                    113:                cvs_sendreq(root, CVS_REQ_LOG, NULL);
                    114:        }
                    115:
1.1       jfb       116:        return (0);
                    117: }
                    118:
                    119:
1.6       jfb       120: /*
                    121:  * cvs_getlog_file()
                    122:  *
                    123:  * Diff a single file.
                    124:  */
                    125: static int
                    126: cvs_getlog_file(CVSFILE *cf, void *arg)
                    127: {
1.7       jfb       128:        char *repo, fpath[MAXPATHLEN];
1.6       jfb       129:        RCSFILE *rf;
                    130:        struct cvsroot *root;
                    131:        struct cvs_ent *entp;
                    132:
1.7       jfb       133:        cvs_file_getpath(cf, fpath, sizeof(fpath));
                    134:
1.6       jfb       135:        if (cf->cf_type == DT_DIR) {
                    136:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    137:                        root = cf->cf_parent->cf_ddat->cd_root;
1.7       jfb       138:                        cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    139:                            CVS_FILE_NAME(cf));
1.9       deraadt   140:                } else {
1.6       jfb       141:                        root = cf->cf_ddat->cd_root;
                    142:                        if ((cf->cf_parent == NULL) ||
                    143:                            (root != cf->cf_parent->cf_ddat->cd_root)) {
                    144:                                cvs_connect(root);
                    145:                        }
                    146:
                    147:                        cvs_senddir(root, cf);
                    148:                }
                    149:
                    150:                return (0);
1.9       deraadt   151:        } else
1.6       jfb       152:                root = cf->cf_parent->cf_ddat->cd_root;
                    153:
                    154:        rf = NULL;
                    155:        if (cf->cf_parent != NULL) {
                    156:                repo = cf->cf_parent->cf_ddat->cd_repo;
1.9       deraadt   157:        } else {
1.6       jfb       158:                repo = NULL;
                    159:        }
                    160:
                    161:        if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    162:                if (root->cr_method == CVS_METHOD_LOCAL)
1.7       jfb       163:                        cvs_printf("? %s\n", fpath);
1.6       jfb       164:                else
1.7       jfb       165:                        cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    166:                            CVS_FILE_NAME(cf));
1.6       jfb       167:                return (0);
                    168:        }
                    169:
1.7       jfb       170:        entp = cvs_ent_getent(fpath);
1.6       jfb       171:        if (entp == NULL)
                    172:                return (-1);
                    173:
                    174:        if ((root->cr_method != CVS_METHOD_LOCAL) &&
                    175:            (cvs_sendentry(root, entp) < 0)) {
                    176:                cvs_ent_free(entp);
                    177:                return (-1);
                    178:        }
                    179:
                    180:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    181:                switch (cf->cf_cvstat) {
                    182:                case CVS_FST_UPTODATE:
1.7       jfb       183:                        cvs_sendreq(root, CVS_REQ_UNCHANGED, CVS_FILE_NAME(cf));
1.6       jfb       184:                        break;
                    185:                case CVS_FST_ADDED:
                    186:                case CVS_FST_MODIFIED:
1.7       jfb       187:                        cvs_sendreq(root, CVS_REQ_ISMODIFIED,
                    188:                            CVS_FILE_NAME(cf));
1.6       jfb       189:                        break;
                    190:                default:
                    191:                        return (-1);
                    192:                }
                    193:
                    194:                cvs_ent_free(entp);
                    195:                return (0);
                    196:        }
1.5       jfb       197:
1.7       jfb       198:        snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
                    199:            root->cr_dir, repo, fpath, RCS_FILE_EXT);
1.5       jfb       200:
1.7       jfb       201:        rf = rcs_open(fpath, RCS_MODE_READ);
1.6       jfb       202:        if (rf == NULL) {
                    203:                cvs_ent_free(entp);
                    204:                return (-1);
                    205:        }
                    206:
                    207:        rcs_close(rf);
                    208:        cvs_ent_free(entp);
                    209:        return (0);
                    210: }
1.5       jfb       211:
                    212: #ifdef notyet
1.1       jfb       213: static void
                    214: cvs_getlog_print(const char *file, RCSFILE *rfp, u_int flags)
                    215: {
                    216:        char numbuf[64], datebuf[64], *sp;
                    217:        struct rcs_delta *rdp;
                    218:
1.6       jfb       219:        cvs_printf("RCS file: %s\nWorking file: %s\n",
1.1       jfb       220:            rfp->rf_path, file);
1.6       jfb       221:        cvs_printf("Working file: %s\n", (char *)NULL);
                    222:        cvs_printf("head: %s\nbranch:\nlocks:\naccess list:\n");
                    223:        cvs_printf("symbolic names:\nkeyword substitutions:\n");
                    224:        cvs_printf("total revisions: %u;\tselected revisions: %u\n", 1, 1);
1.1       jfb       225:
1.6       jfb       226:        cvs_printf("description:\n");
1.1       jfb       227:
                    228:        for (;;) {
1.6       jfb       229:                cvs_printf(CVS_GETLOG_REVSEP "\n");
1.5       jfb       230:                rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
1.6       jfb       231:                cvs_printf("revision %s\n", numbuf);
                    232:                cvs_printf("date: %d/%02d/%d %02d:%02d:%02d;  author: %s;"
1.1       jfb       233:                    "  state: %s;  lines:",
                    234:                    rdp->rd_date.tm_year, rdp->rd_date.tm_mon + 1,
                    235:                    rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    236:                    rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    237:                    rdp->rd_author, rdp->rd_state);
                    238:        }
                    239:
1.6       jfb       240:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.1       jfb       241: }
1.5       jfb       242: #endif