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