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

1.66    ! xsa         1: /*     $OpenBSD: getlog.c,v 1.65 2006/07/07 17:37:17 joris Exp $       */
1.1       jfb         2: /*
1.66    ! xsa         3:  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.57      joris       4:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         5:  *
1.57      joris       6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         9:  *
1.57      joris      10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        17:  */
                     18:
1.51      xsa        19: #include "includes.h"
1.1       jfb        20:
                     21: #include "cvs.h"
1.57      joris      22: #include "diff.h"
1.1       jfb        23: #include "log.h"
1.65      joris      24: #include "remote.h"
1.1       jfb        25:
1.57      joris      26: #define LOG_REVSEP \
                     27: "----------------------------"
1.1       jfb        28:
1.57      joris      29: #define LOG_REVEND \
1.1       jfb        30:  "============================================================================="
                     31:
1.66    ! xsa        32: #define L_HEAD         0x01
        !            33: #define L_HEAD_DESCR   0x02
        !            34: #define L_NAME         0x04
        !            35: #define L_NOTAGS       0x08
        !            36:
1.57      joris      37: void   cvs_log_local(struct cvs_file *);
                     38:
1.66    ! xsa        39: int     runflags = 0;
1.57      joris      40: char   *logrev = NULL;
1.1       jfb        41:
1.29      jfb        42: struct cvs_cmd cvs_cmd_log = {
1.63      joris      43:        CVS_OP_LOG, 0, "log",
1.29      jfb        44:        { "lo" },
                     45:        "Print out history information for files",
                     46:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.30      xsa        47:        "bd:hlNRr:s:tw:",
1.29      jfb        48:        NULL,
1.57      joris      49:        cvs_getlog
1.16      joris      50: };
                     51:
1.57      joris      52: int
                     53: cvs_getlog(int argc, char **argv)
1.1       jfb        54: {
1.16      joris      55:        int ch;
1.57      joris      56:        int flags;
                     57:        char *arg = ".";
                     58:        struct cvs_recursion cr;
1.1       jfb        59:
1.57      joris      60:        rcsnum_flags |= RCSNUM_NO_MAGIC;
                     61:        flags = CR_RECURSE_DIRS;
                     62:
                     63:        while ((ch = getopt(argc, argv, cvs_cmd_log.cmd_opts)) != -1) {
1.16      joris      64:                switch (ch) {
1.66    ! xsa        65:                case 'h':
        !            66:                        runflags |= L_HEAD;
        !            67:                        break;
1.1       jfb        68:                case 'l':
1.57      joris      69:                        flags &= ~CR_RECURSE_DIRS;
1.1       jfb        70:                        break;
1.66    ! xsa        71:                case 'N':
        !            72:                        runflags |= L_NOTAGS;
        !            73:                        break;
        !            74:                case 'R':
        !            75:                        runflags |= L_NAME;
1.1       jfb        76:                case 'r':
1.57      joris      77:                        logrev = optarg;
1.25      xsa        78:                        break;
1.66    ! xsa        79:                case 't':
        !            80:                        runflags |= L_HEAD_DESCR;
        !            81:                        break;
1.1       jfb        82:                default:
1.57      joris      83:                        fatal("%s", cvs_cmd_log.cmd_synopsis);
1.1       jfb        84:                }
                     85:        }
                     86:
1.57      joris      87:        argc -= optind;
                     88:        argv += optind;
1.6       jfb        89:
1.57      joris      90:        cr.enterdir = NULL;
                     91:        cr.leavedir = NULL;
1.65      joris      92:
                     93:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                     94:                cr.fileproc = cvs_client_sendfile;
                     95:
1.66    ! xsa        96:                if (runflags & L_HEAD)
        !            97:                        cvs_client_send_request("Argument -h");
        !            98:
1.65      joris      99:                if (!(flags & CR_RECURSE_DIRS))
                    100:                        cvs_client_send_request("Argument -l");
                    101:
1.66    ! xsa       102:                if (runflags & L_NOTAGS)
        !           103:                        cvs_client_send_request("Argument -N");
        !           104:
        !           105:                if (runflags & L_NAME)
        !           106:                        cvs_client_send_request("Argument -R");
        !           107:
1.65      joris     108:                if (logrev != NULL)
                    109:                        cvs_client_send_request("Argument -r%s", logrev);
1.66    ! xsa       110:
        !           111:                if (runflags & L_HEAD_DESCR)
        !           112:                        cvs_client_send_request("Argument -t");
1.65      joris     113:        } else {
                    114:                cr.fileproc = cvs_log_local;
                    115:        }
                    116:
1.57      joris     117:        cr.flags = flags;
                    118:
                    119:        if (argc > 0)
                    120:                cvs_file_run(argc, argv, &cr);
                    121:        else
                    122:                cvs_file_run(1, &arg, &cr);
1.5       jfb       123:
1.65      joris     124:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                    125:                cvs_client_send_files(argv, argc);
                    126:                cvs_client_senddir(".");
                    127:                cvs_client_send_request("log");
                    128:                cvs_client_get_responses();
                    129:        }
                    130:
1.49      joris     131:        return (0);
1.6       jfb       132: }
1.5       jfb       133:
1.57      joris     134: void
                    135: cvs_log_local(struct cvs_file *cf)
1.1       jfb       136: {
1.57      joris     137:        u_int nrev;
1.20      jfb       138:        struct rcs_sym *sym;
1.57      joris     139:        struct rcs_lock *lkp;
1.1       jfb       140:        struct rcs_delta *rdp;
1.21      jfb       141:        struct rcs_access *acp;
1.57      joris     142:        char numb[32], timeb[32];
1.60      joris     143:
                    144:        cvs_log(LP_TRACE, "cvs_log_local(%s)", cf->file_path);
1.20      jfb       145:
1.61      joris     146:        cvs_file_classify(cf, NULL, 0);
1.39      xsa       147:
1.57      joris     148:        if (cf->file_status == FILE_UNKNOWN) {
                    149:                if (verbosity > 0)
                    150:                        cvs_log(LP_ERR, "nothing known about %s",
                    151:                            cf->file_path);
                    152:                return;
                    153:        } else if (cf->file_status == FILE_ADDED) {
1.39      xsa       154:                if (verbosity > 0)
1.62      david     155:                        cvs_log(LP_ERR, "%s has been added, but not committed",
1.57      joris     156:                            cf->file_path);
1.59      joris     157:                return;
                    158:        }
                    159:
                    160:        if (cf->file_type == CVS_DIR) {
                    161:                if (verbosity > 1)
                    162:                        cvs_log(LP_NOTICE, "Logging %s", cf->file_path);
1.57      joris     163:                return;
1.39      xsa       164:        }
                    165:
1.66    ! xsa       166:        if (runflags & L_NAME) {
        !           167:                cvs_printf("%s\n", cf->file_rpath);
        !           168:                return;
        !           169:        }
        !           170:
1.65      joris     171:        cvs_printf("\nRCS file: %s", cf->file_rpath);
                    172:        cvs_printf("\nWorking file: %s", cf->file_path);
                    173:        cvs_printf("\nhead:");
1.57      joris     174:        if (cf->file_rcs->rf_head != NULL)
1.65      joris     175:                cvs_printf(" %s", rcsnum_tostr(cf->file_rcs->rf_head,
1.57      joris     176:                    numb, sizeof(numb)));
                    177:
1.65      joris     178:        cvs_printf("\nbranch:");
1.57      joris     179:        if (rcs_branch_get(cf->file_rcs) != NULL) {
1.65      joris     180:                cvs_printf(" %s", rcsnum_tostr(rcs_branch_get(cf->file_rcs),
1.57      joris     181:                    numb, sizeof(numb)));
1.20      jfb       182:        }
1.1       jfb       183:
1.65      joris     184:        cvs_printf("\nlocks: %s", (cf->file_rcs->rf_flags & RCS_SLOCK)
1.57      joris     185:            ? "strict" : "");
                    186:        TAILQ_FOREACH(lkp, &(cf->file_rcs->rf_locks), rl_list)
1.65      joris     187:                cvs_printf("\n\t%s: %s", lkp->rl_name,
1.57      joris     188:                    rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.20      jfb       189:
1.65      joris     190:        cvs_printf("\naccess list:\n");
1.57      joris     191:        TAILQ_FOREACH(acp, &(cf->file_rcs->rf_access), ra_list)
1.65      joris     192:                cvs_printf("\t%s\n", acp->ra_name);
1.20      jfb       193:
1.66    ! xsa       194:        if (!(runflags & L_NOTAGS)) {
        !           195:                cvs_printf("symbolic names:\n");
        !           196:                TAILQ_FOREACH(sym, &(cf->file_rcs->rf_symbols), rs_list) {
        !           197:                        cvs_printf("\t%s: %s\n", sym->rs_name,
        !           198:                            rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
        !           199:                }
1.21      jfb       200:        }
                    201:
1.65      joris     202:        cvs_printf("keyword substitution: %s\n",
1.57      joris     203:            cf->file_rcs->rf_expand == NULL ? "kv" : cf->file_rcs->rf_expand);
                    204:
1.65      joris     205:        cvs_printf("total revisions: %u", cf->file_rcs->rf_ndelta);
1.20      jfb       206:
1.57      joris     207:        if (logrev != NULL)
1.58      joris     208:                nrev = cvs_revision_select(cf->file_rcs, logrev);
1.57      joris     209:        else
                    210:                nrev = cf->file_rcs->rf_ndelta;
1.21      jfb       211:
1.66    ! xsa       212:        if (cf->file_rcs->rf_head != NULL &&
        !           213:            !(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR))
        !           214:                cvs_printf(";\tselected revisions: %u", nrev);
        !           215:
1.65      joris     216:        cvs_printf("\n");
1.1       jfb       217:
1.66    ! xsa       218:        if (!(runflags & L_HEAD) || (runflags & L_HEAD_DESCR))
        !           219:                cvs_printf("description:\n%s", cf->file_rcs->rf_desc);
        !           220:
        !           221:        if (!(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR)) {
        !           222:                TAILQ_FOREACH(rdp, &(cf->file_rcs->rf_delta), rd_list) {
        !           223:                        if (logrev != NULL &&
        !           224:                            !(rdp->rd_flags & RCS_RD_SELECT))
        !           225:                                continue;
        !           226:
        !           227:                        cvs_printf("%s\n", LOG_REVSEP);
        !           228:
        !           229:                        rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
        !           230:                        cvs_printf("revision %s", numb);
        !           231:
        !           232:                        strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S",
        !           233:                            &rdp->rd_date);
        !           234:                        cvs_printf("\ndate: %s;  author: %s;  state: %s;\n",
        !           235:                            timeb, rdp->rd_author, rdp->rd_state);
        !           236:                        cvs_printf("%s", rdp->rd_log);
        !           237:                }
1.57      joris     238:        }
1.20      jfb       239:
1.65      joris     240:        cvs_printf("%s\n", LOG_REVEND);
1.1       jfb       241: }