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