[BACK]Return to annotate.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/annotate.c, Revision 1.31

1.31    ! xsa         1: /*     $OpenBSD$       */
1.1       jfb         2: /*
1.31    ! xsa         3:  * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         4:  *
1.31    ! xsa         5:  * Permission to use, copy, modify, and distribute this software for any
        !             6:  * purpose with or without fee is hereby granted, provided that the above
        !             7:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         8:  *
1.31    ! xsa         9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.27      xsa        18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
1.31    ! xsa        22: #include "remote.h"
        !            23:
        !            24: void   cvs_annotate_local(struct cvs_file *);
1.1       jfb        25:
1.31    ! xsa        26: static int      force_head = 0;
        !            27: static char    *rev = NULL;
1.14      jfb        28:
                     29: struct cvs_cmd cvs_cmd_annotate = {
1.31    ! xsa        30:        CVS_OP_ANNOTATE, 0, "annotate",
        !            31:        { "ann", "blame" },
1.14      jfb        32:        "Show last revision where each line was modified",
1.31    ! xsa        33:        "[-flR] [-D date | -r rev] [file ...]",
1.14      jfb        34:        "D:flRr:",
                     35:        NULL,
1.31    ! xsa        36:        cvs_annotate
1.19      joris      37: };
1.1       jfb        38:
1.31    ! xsa        39: int
        !            40: cvs_annotate(int argc, char **argv)
1.1       jfb        41: {
1.31    ! xsa        42:        int ch, flags;
        !            43:        char *arg = ".";
        !            44:        struct cvs_recursion cr;
1.1       jfb        45:
1.31    ! xsa        46:        flags = CR_RECURSE_DIRS;
1.1       jfb        47:
1.31    ! xsa        48:        while ((ch = getopt(argc, argv, cvs_cmd_annotate.cmd_opts)) != -1) {
1.1       jfb        49:                switch (ch) {
                     50:                case 'D':
                     51:                        break;
1.4       jfb        52:                case 'f':
1.31    ! xsa        53:                        force_head = 1;
1.4       jfb        54:                        break;
1.1       jfb        55:                case 'l':
1.31    ! xsa        56:                        flags &= ~CR_RECURSE_DIRS;
1.1       jfb        57:                        break;
                     58:                case 'R':
                     59:                        break;
                     60:                case 'r':
1.4       jfb        61:                        rev = optarg;
1.1       jfb        62:                        break;
                     63:                default:
1.31    ! xsa        64:                        fatal("%s", cvs_cmd_annotate.cmd_synopsis);
1.1       jfb        65:                }
1.4       jfb        66:        }
                     67:
1.31    ! xsa        68:        argc -= optind;
        !            69:        argv += optind;
1.1       jfb        70:
1.31    ! xsa        71:        cr.enterdir = NULL;
        !            72:        cr.leavedir = NULL;
1.1       jfb        73:
1.31    ! xsa        74:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !            75:                cr.fileproc = cvs_client_sendfile;
1.1       jfb        76:
1.31    ! xsa        77:                if (force_head == 1)
        !            78:                        cvs_client_send_request("Argument -f");
1.1       jfb        79:
1.31    ! xsa        80:                if (!(flags & CR_RECURSE_DIRS))
        !            81:                        cvs_client_send_request("Argument -l");
1.1       jfb        82:
1.31    ! xsa        83:                if (rev != NULL)
        !            84:                        cvs_client_send_request("Argument -r%s", rev);
        !            85:        } else {
        !            86:                cr.fileproc = cvs_annotate_local;
1.1       jfb        87:        }
                     88:
1.31    ! xsa        89:        cr.flags = flags;
1.2       jfb        90:
1.31    ! xsa        91:        if (argc > 0)
        !            92:                cvs_file_run(argc, argv, &cr);
        !            93:        else
        !            94:                cvs_file_run(1, &arg, &cr);
        !            95:
        !            96:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !            97:                cvs_client_send_files(argv, argc);
        !            98:                cvs_client_senddir(".");
        !            99:                cvs_client_send_request("annotate");
        !           100:                cvs_client_get_responses();
1.1       jfb       101:        }
1.13      joris     102:
1.25      joris     103:        return (0);
1.18      xsa       104: }
                    105:
1.31    ! xsa       106: void
        !           107: cvs_annotate_local(struct cvs_file *cf)
        !           108: {
        !           109:        struct cvs_line *lp;
        !           110:        struct cvs_lines *lines;
        !           111:        BUF *b;
        !           112:        RCSNUM *ann_rev;
        !           113:        char *content;
        !           114:
        !           115:        ann_rev = NULL;
        !           116:
        !           117:        cvs_log(LP_TRACE, "cvs_annotate_local(%s)", cf->file_path);
1.18      xsa       118:
1.31    ! xsa       119:        cvs_file_classify(cf, NULL, 0);
        !           120:
        !           121:        if (cf->file_status == FILE_UNKNOWN)
        !           122:                return;
1.18      xsa       123:
1.31    ! xsa       124:        cvs_printf("Annotations for %s", cf->file_name);
        !           125:        cvs_printf("\n***************\n");
1.18      xsa       126:
1.31    ! xsa       127:        if (rev != NULL)
        !           128:                ann_rev = rcs_translate_tag(rev, cf->file_rcs);
        !           129:        else {
        !           130:                ann_rev = rcsnum_alloc();
        !           131:                rcsnum_cpy(cf->file_rcs->rf_head, ann_rev, 0);
        !           132:        }
1.18      xsa       133:
1.31    ! xsa       134:        b = rcs_getrev(cf->file_rcs, ann_rev);
        !           135:        cvs_buf_putc(b, '\0');
1.18      xsa       136:
1.31    ! xsa       137:        content = cvs_buf_release(b);
        !           138:        if ((lines = cvs_splitlines(content)) == NULL)
        !           139:                fatal("cvs_annotate_local: cvs_splitlines failed");
1.18      xsa       140:
1.31    ! xsa       141:         xfree(content);
1.18      xsa       142:
1.31    ! xsa       143:        TAILQ_FOREACH(lp, &(lines->l_lines), l_list) {
        !           144:                if (lp->l_line == NULL)
        !           145:                        continue;
1.18      xsa       146:
1.31    ! xsa       147:                cvs_printf("%s\n", lp->l_line);
        !           148:        }
        !           149:         cvs_freelines(lines);
1.18      xsa       150:
1.31    ! xsa       151:        if (ann_rev != NULL)
        !           152:                rcsnum_free(ann_rev);
1.1       jfb       153: }