Annotation of src/usr.bin/cvs/annotate.c, Revision 1.37
1.37 ! otto 1: /* $OpenBSD: annotate.c,v 1.36 2007/02/09 03:49:15 joris Exp $ */
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.37 ! otto 18: #include <sys/param.h>
! 19: #include <sys/dirent.h>
! 20: #include <unistd.h>
1.1 jfb 21:
22: #include "cvs.h"
1.31 xsa 23: #include "remote.h"
24:
25: void cvs_annotate_local(struct cvs_file *);
1.1 jfb 26:
1.31 xsa 27: static int force_head = 0;
28: static char *rev = NULL;
1.14 jfb 29:
30: struct cvs_cmd cvs_cmd_annotate = {
1.31 xsa 31: CVS_OP_ANNOTATE, 0, "annotate",
32: { "ann", "blame" },
1.14 jfb 33: "Show last revision where each line was modified",
1.31 xsa 34: "[-flR] [-D date | -r rev] [file ...]",
1.14 jfb 35: "D:flRr:",
36: NULL,
1.31 xsa 37: cvs_annotate
1.19 joris 38: };
1.1 jfb 39:
1.31 xsa 40: int
41: cvs_annotate(int argc, char **argv)
1.1 jfb 42: {
1.31 xsa 43: int ch, flags;
44: char *arg = ".";
45: struct cvs_recursion cr;
1.1 jfb 46:
1.31 xsa 47: flags = CR_RECURSE_DIRS;
1.1 jfb 48:
1.31 xsa 49: while ((ch = getopt(argc, argv, cvs_cmd_annotate.cmd_opts)) != -1) {
1.1 jfb 50: switch (ch) {
51: case 'D':
52: break;
1.4 jfb 53: case 'f':
1.31 xsa 54: force_head = 1;
1.4 jfb 55: break;
1.1 jfb 56: case 'l':
1.31 xsa 57: flags &= ~CR_RECURSE_DIRS;
1.1 jfb 58: break;
59: case 'R':
60: break;
61: case 'r':
1.4 jfb 62: rev = optarg;
1.1 jfb 63: break;
64: default:
1.31 xsa 65: fatal("%s", cvs_cmd_annotate.cmd_synopsis);
1.1 jfb 66: }
1.4 jfb 67: }
68:
1.31 xsa 69: argc -= optind;
70: argv += optind;
1.1 jfb 71:
1.31 xsa 72: cr.enterdir = NULL;
73: cr.leavedir = NULL;
1.1 jfb 74:
1.31 xsa 75: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.33 joris 76: cvs_client_connect_to_server();
1.31 xsa 77: cr.fileproc = cvs_client_sendfile;
1.1 jfb 78:
1.31 xsa 79: if (force_head == 1)
80: cvs_client_send_request("Argument -f");
1.1 jfb 81:
1.31 xsa 82: if (!(flags & CR_RECURSE_DIRS))
83: cvs_client_send_request("Argument -l");
1.1 jfb 84:
1.31 xsa 85: if (rev != NULL)
86: cvs_client_send_request("Argument -r%s", rev);
87: } else {
88: cr.fileproc = cvs_annotate_local;
1.1 jfb 89: }
90:
1.31 xsa 91: cr.flags = flags;
1.2 jfb 92:
1.31 xsa 93: if (argc > 0)
94: cvs_file_run(argc, argv, &cr);
95: else
96: cvs_file_run(1, &arg, &cr);
97:
98: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
99: cvs_client_send_files(argv, argc);
100: cvs_client_senddir(".");
101: cvs_client_send_request("annotate");
102: cvs_client_get_responses();
1.1 jfb 103: }
1.13 joris 104:
1.25 joris 105: return (0);
1.18 xsa 106: }
107:
1.31 xsa 108: void
109: cvs_annotate_local(struct cvs_file *cf)
110: {
111: cvs_log(LP_TRACE, "cvs_annotate_local(%s)", cf->file_path);
1.18 xsa 112:
1.36 joris 113: cvs_file_classify(cf, NULL);
1.31 xsa 114:
1.32 xsa 115: if (cf->file_status == FILE_UNKNOWN ||
116: cf->file_status == FILE_UNLINK)
1.31 xsa 117: return;
1.18 xsa 118:
1.31 xsa 119: cvs_printf("Annotations for %s", cf->file_name);
120: cvs_printf("\n***************\n");
1.35 joris 121: cvs_printf("no code yet\n");
1.1 jfb 122: }