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

1.88    ! joris       1: /*     $OpenBSD: getlog.c,v 1.87 2008/03/02 19:05:34 tobias 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.71      otto       19: #include <unistd.h>
                     20: #include <string.h>
1.72      niallo     21: #include <errno.h>
1.1       jfb        22:
                     23: #include "cvs.h"
1.65      joris      24: #include "remote.h"
1.1       jfb        25:
1.66      xsa        26: #define L_HEAD         0x01
                     27: #define L_HEAD_DESCR   0x02
                     28: #define L_NAME         0x04
                     29: #define L_NOTAGS       0x08
1.67      xsa        30: #define L_LOGINS       0x10
                     31: #define L_STATES       0x20
1.66      xsa        32:
1.57      joris      33: void   cvs_log_local(struct cvs_file *);
                     34:
1.67      xsa        35: static void    log_rev_print(struct rcs_delta *);
                     36:
1.66      xsa        37: int     runflags = 0;
1.85      joris      38: char   *logrev = NULL;
1.67      xsa        39: char   *slist = NULL;
                     40: char   *wlist = NULL;
1.1       jfb        41:
1.29      jfb        42: struct cvs_cmd cvs_cmd_log = {
1.81      tobias     43:        CVS_OP_LOG, CVS_USE_WDIR, "log",
1.29      jfb        44:        { "lo" },
                     45:        "Print out history information for files",
                     46:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
1.68      xsa        47:        "bd:hlNRr:s:tw:",
1.29      jfb        48:        NULL,
1.57      joris      49:        cvs_getlog
1.16      joris      50: };
                     51:
1.72      niallo     52: struct cvs_cmd cvs_cmd_rlog = {
                     53:        CVS_OP_RLOG, 0, "rlog",
                     54:        { "rlo" },
                     55:        "Print out history information for files",
                     56:        "[-bhlNRt] [-d dates] [-r revisions] [-s states] [-w logins]",
                     57:        "bd:hlNRr:s:tw:",
                     58:        NULL,
                     59:        cvs_getlog
                     60: };
                     61:
1.57      joris      62: int
                     63: cvs_getlog(int argc, char **argv)
1.1       jfb        64: {
1.79      tobias     65:        int ch, flags, i;
1.57      joris      66:        char *arg = ".";
                     67:        struct cvs_recursion cr;
1.1       jfb        68:
1.57      joris      69:        flags = CR_RECURSE_DIRS;
                     70:
1.84      tobias     71:        while ((ch = getopt(argc, argv, cvs_cmdop == CVS_OP_LOG ?
                     72:            cvs_cmd_log.cmd_opts : cvs_cmd_rlog.cmd_opts)) != -1) {
1.16      joris      73:                switch (ch) {
1.66      xsa        74:                case 'h':
                     75:                        runflags |= L_HEAD;
                     76:                        break;
1.1       jfb        77:                case 'l':
1.57      joris      78:                        flags &= ~CR_RECURSE_DIRS;
1.1       jfb        79:                        break;
1.66      xsa        80:                case 'N':
                     81:                        runflags |= L_NOTAGS;
                     82:                        break;
                     83:                case 'R':
                     84:                        runflags |= L_NAME;
1.80      tobias     85:                        break;
1.1       jfb        86:                case 'r':
1.57      joris      87:                        logrev = optarg;
1.25      xsa        88:                        break;
1.67      xsa        89:                case 's':
                     90:                        runflags |= L_STATES;
                     91:                        slist = optarg;
                     92:                        break;
1.66      xsa        93:                case 't':
                     94:                        runflags |= L_HEAD_DESCR;
                     95:                        break;
1.67      xsa        96:                case 'w':
                     97:                        runflags |= L_LOGINS;
                     98:                        wlist = optarg;
                     99:                        break;
1.1       jfb       100:                default:
1.87      tobias    101:                        fatal("%s", cvs_cmdop == CVS_OP_LOG ?
                    102:                            cvs_cmd_log.cmd_synopsis :
                    103:                            cvs_cmd_rlog.cmd_synopsis);
1.1       jfb       104:                }
                    105:        }
                    106:
1.57      joris     107:        argc -= optind;
                    108:        argv += optind;
1.6       jfb       109:
1.79      tobias    110:        if (cvs_cmdop == CVS_OP_RLOG) {
1.81      tobias    111:                flags |= CR_REPO;
                    112:
1.79      tobias    113:                if (argc == 0)
                    114:                        return 0;
                    115:
                    116:                for (i = 0; i < argc; i++)
                    117:                        if (argv[i][0] == '/')
                    118:                                fatal("Absolute path name is invalid: %s",
                    119:                                    argv[i]);
                    120:        }
                    121:
1.57      joris     122:        cr.enterdir = NULL;
                    123:        cr.leavedir = NULL;
1.65      joris     124:
                    125:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.69      joris     126:                cvs_client_connect_to_server();
1.65      joris     127:                cr.fileproc = cvs_client_sendfile;
                    128:
1.66      xsa       129:                if (runflags & L_HEAD)
                    130:                        cvs_client_send_request("Argument -h");
                    131:
1.65      joris     132:                if (!(flags & CR_RECURSE_DIRS))
                    133:                        cvs_client_send_request("Argument -l");
                    134:
1.66      xsa       135:                if (runflags & L_NOTAGS)
                    136:                        cvs_client_send_request("Argument -N");
                    137:
                    138:                if (runflags & L_NAME)
                    139:                        cvs_client_send_request("Argument -R");
                    140:
1.65      joris     141:                if (logrev != NULL)
                    142:                        cvs_client_send_request("Argument -r%s", logrev);
1.66      xsa       143:
1.67      xsa       144:                if (runflags & L_STATES)
                    145:                        cvs_client_send_request("Argument -s%s", slist);
                    146:
1.66      xsa       147:                if (runflags & L_HEAD_DESCR)
                    148:                        cvs_client_send_request("Argument -t");
1.67      xsa       149:
                    150:                if (runflags & L_LOGINS)
                    151:                        cvs_client_send_request("Argument -w%s", wlist);
1.65      joris     152:        } else {
1.75      xsa       153:                if (cvs_cmdop == CVS_OP_RLOG &&
1.72      niallo    154:                    chdir(current_cvsroot->cr_dir) == -1)
1.76      xsa       155:                        fatal("cvs_getlog: %s", strerror(errno));
1.72      niallo    156:
1.65      joris     157:                cr.fileproc = cvs_log_local;
                    158:        }
                    159:
1.57      joris     160:        cr.flags = flags;
                    161:
1.79      tobias    162:        if (cvs_cmdop == CVS_OP_LOG ||
                    163:            current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
                    164:                if (argc > 0)
                    165:                        cvs_file_run(argc, argv, &cr);
                    166:                else
                    167:                        cvs_file_run(1, &arg, &cr);
                    168:        }
1.5       jfb       169:
1.65      joris     170:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                    171:                cvs_client_send_files(argv, argc);
                    172:                cvs_client_senddir(".");
1.75      xsa       173:
                    174:                cvs_client_send_request((cvs_cmdop == CVS_OP_RLOG) ?
                    175:                    "rlog" : "log");
                    176:
1.65      joris     177:                cvs_client_get_responses();
                    178:        }
                    179:
1.49      joris     180:        return (0);
1.6       jfb       181: }
1.5       jfb       182:
1.57      joris     183: void
                    184: cvs_log_local(struct cvs_file *cf)
1.1       jfb       185: {
1.57      joris     186:        u_int nrev;
1.86      joris     187:        RCSNUM *rev;
1.20      jfb       188:        struct rcs_sym *sym;
1.57      joris     189:        struct rcs_lock *lkp;
1.1       jfb       190:        struct rcs_delta *rdp;
1.21      jfb       191:        struct rcs_access *acp;
1.73      xsa       192:        char numb[CVS_REV_BUFSZ];
1.60      joris     193:
                    194:        cvs_log(LP_TRACE, "cvs_log_local(%s)", cf->file_path);
1.20      jfb       195:
1.78      joris     196:        cvs_file_classify(cf, cvs_directory_tag);
1.39      xsa       197:
1.57      joris     198:        if (cf->file_status == FILE_UNKNOWN) {
                    199:                return;
                    200:        } else if (cf->file_status == FILE_ADDED) {
1.39      xsa       201:                if (verbosity > 0)
1.62      david     202:                        cvs_log(LP_ERR, "%s has been added, but not committed",
1.57      joris     203:                            cf->file_path);
1.59      joris     204:                return;
                    205:        }
                    206:
                    207:        if (cf->file_type == CVS_DIR) {
                    208:                if (verbosity > 1)
                    209:                        cvs_log(LP_NOTICE, "Logging %s", cf->file_path);
1.57      joris     210:                return;
1.39      xsa       211:        }
                    212:
1.66      xsa       213:        if (runflags & L_NAME) {
                    214:                cvs_printf("%s\n", cf->file_rpath);
                    215:                return;
                    216:        }
                    217:
1.65      joris     218:        cvs_printf("\nRCS file: %s", cf->file_rpath);
1.74      xsa       219:
                    220:        if (cvs_cmdop != CVS_OP_RLOG)
                    221:                cvs_printf("\nWorking file: %s", cf->file_path);
                    222:
1.65      joris     223:        cvs_printf("\nhead:");
1.57      joris     224:        if (cf->file_rcs->rf_head != NULL)
1.65      joris     225:                cvs_printf(" %s", rcsnum_tostr(cf->file_rcs->rf_head,
1.57      joris     226:                    numb, sizeof(numb)));
                    227:
1.65      joris     228:        cvs_printf("\nbranch:");
1.57      joris     229:        if (rcs_branch_get(cf->file_rcs) != NULL) {
1.65      joris     230:                cvs_printf(" %s", rcsnum_tostr(rcs_branch_get(cf->file_rcs),
1.57      joris     231:                    numb, sizeof(numb)));
1.20      jfb       232:        }
1.1       jfb       233:
1.65      joris     234:        cvs_printf("\nlocks: %s", (cf->file_rcs->rf_flags & RCS_SLOCK)
1.57      joris     235:            ? "strict" : "");
                    236:        TAILQ_FOREACH(lkp, &(cf->file_rcs->rf_locks), rl_list)
1.65      joris     237:                cvs_printf("\n\t%s: %s", lkp->rl_name,
1.57      joris     238:                    rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.20      jfb       239:
1.65      joris     240:        cvs_printf("\naccess list:\n");
1.57      joris     241:        TAILQ_FOREACH(acp, &(cf->file_rcs->rf_access), ra_list)
1.65      joris     242:                cvs_printf("\t%s\n", acp->ra_name);
1.20      jfb       243:
1.66      xsa       244:        if (!(runflags & L_NOTAGS)) {
                    245:                cvs_printf("symbolic names:\n");
                    246:                TAILQ_FOREACH(sym, &(cf->file_rcs->rf_symbols), rs_list) {
1.86      joris     247:                        rev = rcsnum_alloc();
                    248:                        rcsnum_cpy(sym->rs_num, rev, 0);
1.85      joris     249:                        if (RCSNUM_ISBRANCH(sym->rs_num))
1.86      joris     250:                                rcsnum_addmagic(rev);
1.85      joris     251:
1.66      xsa       252:                        cvs_printf("\t%s: %s\n", sym->rs_name,
1.86      joris     253:                            rcsnum_tostr(rev, numb, sizeof(numb)));
                    254:                        rcsnum_free(rev);
1.66      xsa       255:                }
1.21      jfb       256:        }
                    257:
1.65      joris     258:        cvs_printf("keyword substitution: %s\n",
1.57      joris     259:            cf->file_rcs->rf_expand == NULL ? "kv" : cf->file_rcs->rf_expand);
                    260:
1.65      joris     261:        cvs_printf("total revisions: %u", cf->file_rcs->rf_ndelta);
1.20      jfb       262:
1.57      joris     263:        if (logrev != NULL)
1.58      joris     264:                nrev = cvs_revision_select(cf->file_rcs, logrev);
1.57      joris     265:        else
                    266:                nrev = cf->file_rcs->rf_ndelta;
1.21      jfb       267:
1.66      xsa       268:        if (cf->file_rcs->rf_head != NULL &&
                    269:            !(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR))
                    270:                cvs_printf(";\tselected revisions: %u", nrev);
                    271:
1.65      joris     272:        cvs_printf("\n");
1.1       jfb       273:
1.66      xsa       274:        if (!(runflags & L_HEAD) || (runflags & L_HEAD_DESCR))
                    275:                cvs_printf("description:\n%s", cf->file_rcs->rf_desc);
                    276:
                    277:        if (!(runflags & L_HEAD) && !(runflags & L_HEAD_DESCR)) {
                    278:                TAILQ_FOREACH(rdp, &(cf->file_rcs->rf_delta), rd_list) {
1.67      xsa       279:                        /*
                    280:                         * if selections are enabled verify that entry is
                    281:                         * selected.
                    282:                         */
                    283:                        if (logrev == NULL || (rdp->rd_flags & RCS_RD_SELECT))
                    284:                                log_rev_print(rdp);
1.66      xsa       285:                }
1.57      joris     286:        }
1.20      jfb       287:
1.65      joris     288:        cvs_printf("%s\n", LOG_REVEND);
1.67      xsa       289: }
                    290:
                    291: static void
                    292: log_rev_print(struct rcs_delta *rdp)
                    293: {
                    294:        int i, found;
1.73      xsa       295:        char numb[CVS_REV_BUFSZ], timeb[CVS_TIME_BUFSZ];
1.67      xsa       296:        struct cvs_argvector *sargv, *wargv;
1.82      joris     297:        struct rcs_branch *rb;
                    298:        struct rcs_delta *nrdp;
1.67      xsa       299:
                    300:        i = found = 0;
                    301:
                    302:        /* -s states */
                    303:        if (runflags & L_STATES) {
                    304:                sargv = cvs_strsplit(slist, ",");
                    305:                for (i = 0; sargv->argv[i] != NULL; i++) {
                    306:                        if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
                    307:                                found++;
                    308:                                break;
                    309:                        }
                    310:                        found = 0;
                    311:                }
                    312:                cvs_argv_destroy(sargv);
                    313:        }
                    314:
                    315:        /* -w[logins] */
                    316:        if (runflags & L_LOGINS) {
                    317:                wargv = cvs_strsplit(wlist, ",");
                    318:                for (i = 0; wargv->argv[i] != NULL; i++) {
                    319:                        if (strcmp(rdp->rd_author, wargv->argv[i]) == 0) {
                    320:                                found++;
                    321:                                break;
                    322:                        }
                    323:                        found = 0;
                    324:                }
                    325:                cvs_argv_destroy(wargv);
                    326:        }
                    327:
1.68      xsa       328:        if ((runflags & (L_STATES|L_LOGINS)) && found == 0)
1.67      xsa       329:                return;
                    330:
                    331:        cvs_printf("%s\n", LOG_REVSEP);
                    332:
                    333:        rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
                    334:        cvs_printf("revision %s", numb);
                    335:
                    336:        strftime(timeb, sizeof(timeb), "%Y/%m/%d %H:%M:%S", &rdp->rd_date);
1.82      joris     337:        cvs_printf("\ndate: %s;  author: %s;  state: %s;",
1.67      xsa       338:            timeb, rdp->rd_author, rdp->rd_state);
1.82      joris     339:
                    340:        /*
                    341:         * If we are a branch revision, the diff of this revision is stored
                    342:         * in place.
                    343:         * Otherwise, it is stored in the previous revision as a reversed diff.
                    344:         */
                    345:        if (RCSNUM_ISBRANCHREV(rdp->rd_num))
                    346:                nrdp = rdp;
                    347:        else
                    348:                nrdp = TAILQ_NEXT(rdp, rd_list);
                    349:
                    350:        /*
                    351:         * We do not write diff stats for the first revision of the default
                    352:         * branch, since it was not a diff but a full text.
                    353:         */
                    354:        if (nrdp != NULL && rdp->rd_num->rn_len == nrdp->rd_num->rn_len) {
                    355:                int added, removed;
                    356:                rcs_delta_stats(nrdp, &added, &removed);
                    357:                if (RCSNUM_ISBRANCHREV(rdp->rd_num))
                    358:                        cvs_printf("  lines: +%d -%d", added, removed);
                    359:                else
                    360:                        cvs_printf("  lines: +%d -%d", removed, added);
                    361:        }
                    362:        cvs_printf("\n");
                    363:
                    364:        if (!TAILQ_EMPTY(&(rdp->rd_branches))) {
                    365:                cvs_printf("branches:");
                    366:                TAILQ_FOREACH(rb, &(rdp->rd_branches), rb_list) {
                    367:                        RCSNUM *branch;
                    368:                        branch = rcsnum_revtobr(rb->rb_num);
                    369:                        rcsnum_tostr(branch, numb, sizeof(numb));
                    370:                        cvs_printf("  %s;", numb);
                    371:                        rcsnum_free(branch);
                    372:                }
                    373:                cvs_printf("\n");
                    374:        }
1.83      xsa       375:
1.67      xsa       376:        cvs_printf("%s", rdp->rd_log);
1.1       jfb       377: }