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

1.19    ! joris       1: /*     $OpenBSD: getlog.c,v 1.18 2005/04/11 18:02:58 joris 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.10      tedu       50: #ifdef notyet
1.1       jfb        51: static void cvs_getlog_print   (const char *, RCSFILE *, u_int);
1.8       jfb        52: #endif
1.6       jfb        53: static int  cvs_getlog_file    (CVSFILE *, void *);
1.1       jfb        54:
1.16      joris      55: int cvs_getlog_options(char *, int, char **, int *);
1.1       jfb        56:
1.16      joris      57: struct cvs_cmd_info cvs_getlog = {
                     58:        cvs_getlog_options,
                     59:        NULL,
                     60:        cvs_getlog_file,
                     61:        NULL, NULL,
                     62:        CF_RECURSE,
                     63:        CVS_REQ_LOG,
                     64:        CVS_CMD_SENDDIR | CVS_CMD_ALLOWSPEC | CVS_CMD_SENDARGS2
                     65: };
                     66:
                     67: static int rfonly = 0;
                     68: static int honly = 0;
1.1       jfb        69:
                     70: int
1.16      joris      71: cvs_getlog_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        72: {
1.16      joris      73:        int ch;
1.1       jfb        74:
1.16      joris      75:        while ((ch = getopt(argc, argv, opt)) != -1) {
                     76:                switch (ch) {
1.1       jfb        77:                case 'd':
                     78:                        break;
                     79:                case 'h':
                     80:                        honly = 1;
                     81:                        break;
                     82:                case 'l':
1.16      joris      83:                        cvs_getlog.file_flags &= ~CF_RECURSE;
1.1       jfb        84:                        break;
                     85:                case 'R':
                     86:                        rfonly = 1;
                     87:                        break;
                     88:                case 'r':
                     89:                        break;
                     90:                default:
1.19    ! joris      91:                        return (CVS_EX_USAGE);
1.1       jfb        92:                }
                     93:        }
                     94:
1.16      joris      95:        *arg = optind;
1.1       jfb        96:        return (0);
                     97: }
                     98:
                     99:
1.6       jfb       100: /*
                    101:  * cvs_getlog_file()
                    102:  *
                    103:  * Diff a single file.
                    104:  */
                    105: static int
                    106: cvs_getlog_file(CVSFILE *cf, void *arg)
                    107: {
1.12      jfb       108:        int ret;
1.7       jfb       109:        char *repo, fpath[MAXPATHLEN];
1.6       jfb       110:        RCSFILE *rf;
                    111:        struct cvsroot *root;
                    112:        struct cvs_ent *entp;
                    113:
1.12      jfb       114:        ret = 0;
                    115:        rf = NULL;
                    116:        root = CVS_DIR_ROOT(cf);
                    117:        repo = CVS_DIR_REPO(cf);
1.7       jfb       118:
1.13      jfb       119:        if (cf->cf_type == DT_DIR) {
                    120:                if (root->cr_method != CVS_METHOD_LOCAL) {
                    121:                        if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    122:                                ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    123:                                    CVS_FILE_NAME(cf));
                    124:                        else
                    125:                                ret = cvs_senddir(root, cf);
                    126:                }
                    127:
1.12      jfb       128:                return (ret);
1.6       jfb       129:        }
                    130:
1.12      jfb       131:        cvs_file_getpath(cf, fpath, sizeof(fpath));
1.7       jfb       132:        entp = cvs_ent_getent(fpath);
1.6       jfb       133:
1.12      jfb       134:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    135:                if ((entp != NULL) && (cvs_sendentry(root, entp) < 0)) {
                    136:                        cvs_ent_free(entp);
1.19    ! joris     137:                        return (CVS_EX_PROTO);
1.12      jfb       138:                }
1.6       jfb       139:
                    140:                switch (cf->cf_cvstat) {
1.12      jfb       141:                case CVS_FST_UNKNOWN:
                    142:                        ret = cvs_sendreq(root, CVS_REQ_QUESTIONABLE,
                    143:                            CVS_FILE_NAME(cf));
                    144:                        break;
1.6       jfb       145:                case CVS_FST_UPTODATE:
1.12      jfb       146:                        ret = cvs_sendreq(root, CVS_REQ_UNCHANGED,
                    147:                            CVS_FILE_NAME(cf));
1.6       jfb       148:                        break;
                    149:                case CVS_FST_ADDED:
                    150:                case CVS_FST_MODIFIED:
1.12      jfb       151:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
1.7       jfb       152:                            CVS_FILE_NAME(cf));
1.6       jfb       153:                        break;
                    154:                default:
1.12      jfb       155:                        break;
                    156:                }
                    157:        } else {
                    158:                if (cf->cf_cvstat == CVS_FST_UNKNOWN) {
                    159:                        cvs_printf("? %s\n", fpath);
                    160:                        return (0);
                    161:                }
                    162:
                    163:                snprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
                    164:                    root->cr_dir, repo, CVS_FILE_NAME(cf), RCS_FILE_EXT);
                    165:
1.14      jfb       166:                rf = rcs_open(fpath, RCS_READ);
1.12      jfb       167:                if (rf == NULL) {
1.15      tedu      168:                        if (entp != NULL)
                    169:                                cvs_ent_free(entp);
1.19    ! joris     170:                        return (CVS_EX_DATA);
1.6       jfb       171:                }
                    172:
1.12      jfb       173:                rcs_close(rf);
1.6       jfb       174:        }
1.5       jfb       175:
1.12      jfb       176:        if (entp != NULL)
1.6       jfb       177:                cvs_ent_free(entp);
1.12      jfb       178:        return (ret);
1.6       jfb       179: }
1.5       jfb       180:
                    181: #ifdef notyet
1.1       jfb       182: static void
                    183: cvs_getlog_print(const char *file, RCSFILE *rfp, u_int flags)
                    184: {
                    185:        char numbuf[64], datebuf[64], *sp;
                    186:        struct rcs_delta *rdp;
                    187:
1.6       jfb       188:        cvs_printf("RCS file: %s\nWorking file: %s\n",
1.1       jfb       189:            rfp->rf_path, file);
1.6       jfb       190:        cvs_printf("Working file: %s\n", (char *)NULL);
                    191:        cvs_printf("head: %s\nbranch:\nlocks:\naccess list:\n");
                    192:        cvs_printf("symbolic names:\nkeyword substitutions:\n");
                    193:        cvs_printf("total revisions: %u;\tselected revisions: %u\n", 1, 1);
1.1       jfb       194:
1.6       jfb       195:        cvs_printf("description:\n");
1.1       jfb       196:
                    197:        for (;;) {
1.6       jfb       198:                cvs_printf(CVS_GETLOG_REVSEP "\n");
1.5       jfb       199:                rcsnum_tostr(rdp->rd_num, numbuf, sizeof(numbuf));
1.6       jfb       200:                cvs_printf("revision %s\n", numbuf);
                    201:                cvs_printf("date: %d/%02d/%d %02d:%02d:%02d;  author: %s;"
1.1       jfb       202:                    "  state: %s;  lines:",
                    203:                    rdp->rd_date.tm_year, rdp->rd_date.tm_mon + 1,
                    204:                    rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    205:                    rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    206:                    rdp->rd_author, rdp->rd_state);
                    207:        }
                    208:
1.6       jfb       209:        cvs_printf(CVS_GETLOG_REVEND "\n");
1.1       jfb       210: }
1.5       jfb       211: #endif