1 /* $OpenBSD: commit.c,v 1.142 2008/06/14 04:34:08 tobias Exp $ */ 2 /* 3 * Copyright (c) 2006 Joris Vink <joris@openbsd.org> 4 * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> 5 * 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. 9 * 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. 17 */ 18 19 #include <sys/stat.h> 20 21 #include <errno.h> 22 #include <fcntl.h> 23 #include <libgen.h> 24 #include <string.h> 25 #include <unistd.h> 26 27 #include "cvs.h" 28 #include "diff.h" 29 #include "remote.h" 30 31 void cvs_commit_local(struct cvs_file *); 32 void cvs_commit_check_files(struct cvs_file *); 33 void cvs_commit_loginfo(char *); 34 void cvs_commit_lock_dirs(struct cvs_file *); 35 36 static BUF *commit_diff(struct cvs_file *, RCSNUM *, int); 37 static void commit_desc_set(struct cvs_file *); 38 39 struct file_info_list files_info; 40 struct trigger_list *line_list; 41 42 struct cvs_flisthead files_affected; 43 struct cvs_flisthead files_added; 44 struct cvs_flisthead files_removed; 45 struct cvs_flisthead files_modified; 46 47 int conflicts_found; 48 char *logmsg = NULL; 49 char *loginfo = NULL; 50 51 struct cvs_cmd cvs_cmd_commit = { 52 CVS_OP_COMMIT, CVS_USE_WDIR | CVS_LOCK_REPO, "commit", 53 { "ci", "com" }, 54 "Check files into the repository", 55 "[-flR] [-F logfile | -m msg] [-r rev] ...", 56 "F:flm:Rr:", 57 NULL, 58 cvs_commit 59 }; 60 61 int 62 cvs_commit(int argc, char **argv) 63 { 64 int flags; 65 int ch, Fflag, mflag; 66 struct module_checkout *mc; 67 struct cvs_recursion cr; 68 struct cvs_filelist *l; 69 struct file_info *fi; 70 char *arg = ".", repo[MAXPATHLEN]; 71 72 flags = CR_RECURSE_DIRS; 73 Fflag = mflag = 0; 74 75 while ((ch = getopt(argc, argv, cvs_cmd_commit.cmd_opts)) != -1) { 76 switch (ch) { 77 case 'F': 78 /* free previously assigned value */ 79 if (logmsg != NULL) 80 xfree(logmsg); 81 logmsg = cvs_logmsg_read(optarg); 82 Fflag = 1; 83 break; 84 case 'f': 85 break; 86 case 'l': 87 flags &= ~CR_RECURSE_DIRS; 88 break; 89 case 'm': 90 /* free previously assigned value */ 91 if (logmsg != NULL) 92 xfree(logmsg); 93 logmsg = xstrdup(optarg); 94 mflag = 1; 95 break; 96 case 'R': 97 flags |= CR_RECURSE_DIRS; 98 break; 99 case 'r': 100 break; 101 default: 102 fatal("%s", cvs_cmd_commit.cmd_synopsis); 103 } 104 } 105 106 argc -= optind; 107 argv += optind; 108 109 /* -F and -m are mutually exclusive */ 110 if (Fflag && mflag) 111 fatal("cannot specify both a log file and a message"); 112 113 TAILQ_INIT(&files_affected); 114 TAILQ_INIT(&files_added); 115 TAILQ_INIT(&files_removed); 116 TAILQ_INIT(&files_modified); 117 118 TAILQ_INIT(&files_info); 119 conflicts_found = 0; 120 121 cr.enterdir = NULL; 122 cr.leavedir = NULL; 123 cr.fileproc = cvs_commit_check_files; 124 cr.flags = flags; 125 126 if (argc > 0) 127 cvs_file_run(argc, argv, &cr); 128 else 129 cvs_file_run(1, &arg, &cr); 130 131 if (conflicts_found != 0) 132 fatal("%d conflicts found, please correct these first", 133 conflicts_found); 134 135 if (TAILQ_EMPTY(&files_affected)) 136 return (0); 137 138 if (logmsg == NULL && cvs_server_active == 0) { 139 logmsg = cvs_logmsg_create(NULL, &files_added, &files_removed, 140 &files_modified); 141 142 if (logmsg == NULL) 143 fatal("This shouldnt happen, honestly!"); 144 } 145 146 if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) { 147 cvs_client_connect_to_server(); 148 cr.fileproc = cvs_client_sendfile; 149 150 if (argc > 0) 151 cvs_file_run(argc, argv, &cr); 152 else 153 cvs_file_run(1, &arg, &cr); 154 155 if (!(flags & CR_RECURSE_DIRS)) 156 cvs_client_send_request("Argument -l"); 157 158 cvs_client_send_logmsg(logmsg); 159 cvs_client_send_files(argv, argc); 160 cvs_client_senddir("."); 161 cvs_client_send_request("ci"); 162 cvs_client_get_responses(); 163 } else { 164 if (cvs_server_active && logmsg == NULL) 165 fatal("no log message specified"); 166 167 cvs_get_repository_name(".", repo, MAXPATHLEN); 168 169 line_list = cvs_trigger_getlines(CVS_PATH_COMMITINFO, repo); 170 if (line_list != NULL) { 171 TAILQ_FOREACH(l, &files_affected, flist) { 172 fi = xcalloc(1, sizeof(*fi)); 173 fi->file_path = xstrdup(l->file_path); 174 TAILQ_INSERT_TAIL(&files_info, fi, 175 flist); 176 } 177 178 if (cvs_trigger_handle(CVS_TRIGGER_COMMITINFO, 179 repo, NULL, line_list, &files_info)) { 180 cvs_log(LP_ERR, 181 "Pre-commit check failed"); 182 cvs_trigger_freelist(line_list); 183 goto end; 184 } 185 186 cvs_trigger_freelist(line_list); 187 cvs_trigger_freeinfo(&files_info); 188 } 189 190 if (cvs_logmsg_verify(logmsg)) 191 goto end; 192 193 cr.fileproc = cvs_commit_lock_dirs; 194 cvs_file_walklist(&files_affected, &cr); 195 196 line_list = cvs_trigger_getlines(CVS_PATH_LOGINFO, repo); 197 198 cr.fileproc = cvs_commit_local; 199 cvs_file_walklist(&files_affected, &cr); 200 201 if (line_list != NULL) { 202 cvs_commit_loginfo(repo); 203 204 cvs_trigger_handle(CVS_TRIGGER_LOGINFO, repo, 205 loginfo, line_list, &files_info); 206 207 xfree(loginfo); 208 cvs_trigger_freelist(line_list); 209 cvs_trigger_freeinfo(&files_info); 210 } 211 212 mc = cvs_module_lookup(repo); 213 if (mc->mc_prog != NULL && 214 (mc->mc_flags & MODULE_RUN_ON_COMMIT)) 215 cvs_exec(mc->mc_prog, NULL, 0); 216 } 217 218 end: 219 cvs_trigger_freeinfo(&files_info); 220 xfree(logmsg); 221 return (0); 222 } 223 224 void 225 cvs_commit_loginfo(char *repo) 226 { 227 BUF *buf; 228 char pwd[MAXPATHLEN]; 229 struct cvs_filelist *cf; 230 231 if (getcwd(pwd, sizeof(pwd)) == NULL) 232 fatal("Can't get working directory"); 233 234 buf = cvs_buf_alloc(1024); 235 236 cvs_trigger_loginfo_header(buf, repo); 237 238 if (!TAILQ_EMPTY(&files_added)) { 239 cvs_buf_puts(buf, "Added Files:"); 240 241 TAILQ_FOREACH(cf, &files_added, flist) { 242 cvs_buf_putc(buf, '\n'); 243 cvs_buf_putc(buf, '\t'); 244 cvs_buf_puts(buf, cf->file_path); 245 } 246 247 cvs_buf_putc(buf, '\n'); 248 } 249 250 if (!TAILQ_EMPTY(&files_modified)) { 251 cvs_buf_puts(buf, "Modified Files:"); 252 253 TAILQ_FOREACH(cf, &files_modified, flist) { 254 cvs_buf_putc(buf, '\n'); 255 cvs_buf_putc(buf, '\t'); 256 cvs_buf_puts(buf, cf->file_path); 257 } 258 259 cvs_buf_putc(buf, '\n'); 260 } 261 262 if (!TAILQ_EMPTY(&files_removed)) { 263 cvs_buf_puts(buf, "Removed Files:"); 264 265 TAILQ_FOREACH(cf, &files_removed, flist) { 266 cvs_buf_putc(buf, '\n'); 267 cvs_buf_putc(buf, '\t'); 268 cvs_buf_puts(buf, cf->file_path); 269 } 270 271 cvs_buf_putc(buf, '\n'); 272 } 273 274 cvs_buf_puts(buf, "Log Message:\n"); 275 276 cvs_buf_puts(buf, logmsg); 277 278 cvs_buf_putc(buf, '\n'); 279 cvs_buf_putc(buf, '\0'); 280 281 loginfo = cvs_buf_release(buf); 282 } 283 284 void 285 cvs_commit_lock_dirs(struct cvs_file *cf) 286 { 287 char repo[MAXPATHLEN]; 288 289 cvs_get_repository_path(cf->file_wd, repo, sizeof(repo)); 290 cvs_log(LP_TRACE, "cvs_commit_lock_dirs: %s", repo); 291 292 /* locks stay in place until we are fully done and exit */ 293 cvs_repository_lock(repo, 1); 294 } 295 296 void 297 cvs_commit_check_files(struct cvs_file *cf) 298 { 299 char *tag; 300 RCSNUM *branch, *brev; 301 302 branch = brev = NULL; 303 304 cvs_log(LP_TRACE, "cvs_commit_check_files(%s)", cf->file_path); 305 306 if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) 307 cvs_remote_classify_file(cf); 308 else 309 cvs_file_classify(cf, cvs_directory_tag); 310 311 if (cf->file_type == CVS_DIR) { 312 if (verbosity > 1) 313 cvs_log(LP_NOTICE, "Examining %s", cf->file_path); 314 return; 315 } 316 317 if (cf->file_status == FILE_UPTODATE) 318 return; 319 320 if (cf->file_status == FILE_MERGE || 321 cf->file_status == FILE_PATCH || 322 cf->file_status == FILE_CHECKOUT || 323 cf->file_status == FILE_LOST || 324 cf->file_status == FILE_UNLINK) { 325 cvs_log(LP_ERR, "conflict: %s is not up-to-date", 326 cf->file_path); 327 conflicts_found++; 328 return; 329 } 330 331 if (cf->file_status == FILE_CONFLICT && 332 cf->file_ent->ce_conflict != NULL) { 333 cvs_log(LP_ERR, "conflict: unresolved conflicts in %s from " 334 "merging, please fix these first", cf->file_path); 335 conflicts_found++; 336 return; 337 } 338 339 if (cf->file_status == FILE_MODIFIED && 340 cf->file_ent->ce_conflict != NULL && 341 update_has_conflict_markers(cf)) { 342 cvs_log(LP_ERR, "warning: file %s seems to still contain " 343 "conflict indicators", cf->file_path); 344 } 345 346 if (cf->file_ent != NULL && cf->file_ent->ce_date != -1) { 347 cvs_log(LP_ERR, "conflict: cannot commit to sticky date for %s", 348 cf->file_path); 349 conflicts_found++; 350 return; 351 } 352 353 if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) { 354 tag = cvs_directory_tag; 355 if (cf->file_ent != NULL) 356 tag = cf->file_ent->ce_tag; 357 358 if (tag != NULL && cf->file_rcs != NULL) { 359 brev = rcs_sym_getrev(cf->file_rcs, tag); 360 if (brev != NULL) { 361 if (RCSNUM_ISBRANCH(brev)) 362 goto next; 363 rcsnum_free(brev); 364 } 365 366 brev = rcs_translate_tag(tag, cf->file_rcs); 367 368 if (brev == NULL) { 369 fatal("failed to resolve tag: %s", 370 cf->file_ent->ce_tag); 371 } 372 373 if ((branch = rcsnum_revtobr(brev)) == NULL) { 374 cvs_log(LP_ERR, "sticky tag %s is not " 375 "a branch for file %s", tag, 376 cf->file_path); 377 conflicts_found++; 378 rcsnum_free(brev); 379 return; 380 } 381 382 if (!RCSNUM_ISBRANCHREV(brev)) { 383 cvs_log(LP_ERR, "sticky tag %s is not " 384 "a branch for file %s", tag, 385 cf->file_path); 386 conflicts_found++; 387 rcsnum_free(branch); 388 rcsnum_free(brev); 389 return; 390 } 391 392 if (!RCSNUM_ISBRANCH(branch)) { 393 cvs_log(LP_ERR, "sticky tag %s is not " 394 "a branch for file %s", tag, 395 cf->file_path); 396 conflicts_found++; 397 rcsnum_free(branch); 398 rcsnum_free(brev); 399 return; 400 } 401 } 402 } 403 404 next: 405 if (branch != NULL) 406 rcsnum_free(branch); 407 if (brev != NULL) 408 rcsnum_free(brev); 409 410 if (cf->file_status != FILE_ADDED && 411 cf->file_status != FILE_REMOVED && 412 cf->file_status != FILE_MODIFIED) 413 return; 414 415 cvs_file_get(cf->file_path, 0, &files_affected); 416 417 switch (cf->file_status) { 418 case FILE_ADDED: 419 cvs_file_get(cf->file_path, 0, &files_added); 420 break; 421 case FILE_REMOVED: 422 cvs_file_get(cf->file_path, 0, &files_removed); 423 break; 424 case FILE_MODIFIED: 425 cvs_file_get(cf->file_path, 0, &files_modified); 426 break; 427 } 428 } 429 430 void 431 cvs_commit_local(struct cvs_file *cf) 432 { 433 char *tag; 434 BUF *b, *d; 435 int onbranch, isnew, histtype; 436 RCSNUM *nrev, *crev, *rrev, *brev; 437 int openflags, rcsflags; 438 char rbuf[CVS_REV_BUFSZ], nbuf[CVS_REV_BUFSZ]; 439 CVSENTRIES *entlist; 440 char attic[MAXPATHLEN], repo[MAXPATHLEN], rcsfile[MAXPATHLEN]; 441 struct file_info *fi; 442 443 cvs_log(LP_TRACE, "cvs_commit_local(%s)", cf->file_path); 444 cvs_file_classify(cf, cvs_directory_tag); 445 446 if (cvs_noexec == 1) 447 return; 448 449 if (cf->file_type != CVS_FILE) 450 fatal("cvs_commit_local: '%s' is not a file", cf->file_path); 451 452 if (cf->file_status != FILE_MODIFIED && 453 cf->file_status != FILE_ADDED && 454 cf->file_status != FILE_REMOVED) { 455 cvs_log(LP_ERR, "skipping bogus file `%s'", cf->file_path); 456 return; 457 } 458 459 onbranch = 0; 460 nrev = RCS_HEAD_REV; 461 crev = NULL; 462 rrev = NULL; 463 464 if (cf->file_rcs != NULL && cf->file_rcs->rf_branch != NULL) { 465 rcsnum_free(cf->file_rcs->rf_branch); 466 cf->file_rcs->rf_branch = NULL; 467 } 468 469 if (cf->file_status == FILE_MODIFIED || 470 cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED 471 && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1)) { 472 rrev = rcs_head_get(cf->file_rcs); 473 crev = rcs_head_get(cf->file_rcs); 474 if (crev == NULL || rrev == NULL) 475 fatal("no head revision in RCS file for %s", 476 cf->file_path); 477 478 tag = cvs_directory_tag; 479 if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL) 480 tag = cf->file_ent->ce_tag; 481 482 if (tag != NULL) { 483 rcsnum_free(crev); 484 rcsnum_free(rrev); 485 brev = rcs_sym_getrev(cf->file_rcs, tag); 486 crev = rcs_translate_tag(tag, cf->file_rcs); 487 if (brev == NULL || crev == NULL) { 488 fatal("failed to resolve existing tag: %s", 489 tag); 490 } 491 492 rrev = rcsnum_alloc(); 493 rcsnum_cpy(brev, rrev, brev->rn_len - 1); 494 495 if (RCSNUM_ISBRANCHREV(crev) && 496 rcsnum_cmp(crev, rrev, 0)) { 497 nrev = rcsnum_alloc(); 498 rcsnum_cpy(crev, nrev, 0); 499 rcsnum_inc(nrev); 500 } else if (!RCSNUM_ISBRANCH(crev)) { 501 nrev = rcsnum_brtorev(brev); 502 if (nrev == NULL) 503 fatal("failed to create branch rev"); 504 } else { 505 fatal("this isnt suppose to happen, honestly"); 506 } 507 508 rcsnum_free(brev); 509 rcsnum_free(rrev); 510 rrev = rcsnum_branch_root(nrev); 511 512 /* branch stuff was checked in cvs_commit_check_files */ 513 onbranch = 1; 514 } 515 516 rcsnum_tostr(crev, rbuf, sizeof(rbuf)); 517 } else { 518 strlcpy(rbuf, "Non-existent", sizeof(rbuf)); 519 } 520 521 if (rrev != NULL) 522 rcsnum_free(rrev); 523 isnew = 0; 524 if (cf->file_status == FILE_ADDED) { 525 isnew = 1; 526 rcsflags = RCS_CREATE; 527 openflags = O_CREAT | O_TRUNC | O_WRONLY; 528 if (cf->file_rcs != NULL) { 529 if (cf->in_attic == 0) 530 cvs_log(LP_ERR, "warning: expected %s " 531 "to be in the Attic", cf->file_path); 532 533 if (cf->file_rcs->rf_dead == 0) 534 cvs_log(LP_ERR, "warning: expected %s " 535 "to be dead", cf->file_path); 536 537 cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN); 538 (void)xsnprintf(rcsfile, MAXPATHLEN, "%s/%s%s", 539 repo, cf->file_name, RCS_FILE_EXT); 540 541 if (rename(cf->file_rpath, rcsfile) == -1) 542 fatal("cvs_commit_local: failed to move %s " 543 "outside the Attic: %s", cf->file_path, 544 strerror(errno)); 545 546 xfree(cf->file_rpath); 547 cf->file_rpath = xstrdup(rcsfile); 548 549 rcsflags = RCS_READ | RCS_PARSE_FULLY; 550 openflags = O_RDONLY; 551 rcs_close(cf->file_rcs); 552 isnew = 0; 553 } 554 555 cf->repo_fd = open(cf->file_rpath, openflags); 556 if (cf->repo_fd < 0) 557 fatal("cvs_commit_local: %s", strerror(errno)); 558 559 cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd, 560 rcsflags, 0444); 561 if (cf->file_rcs == NULL) 562 fatal("cvs_commit_local: failed to create RCS file " 563 "for %s", cf->file_path); 564 565 commit_desc_set(cf); 566 } 567 568 if (verbosity > 1) { 569 cvs_printf("Checking in %s:\n", cf->file_path); 570 cvs_printf("%s <- %s\n", cf->file_rpath, cf->file_path); 571 cvs_printf("old revision: %s; ", rbuf); 572 } 573 574 if (isnew == 0 && cf->file_rcs->rf_head == NULL) 575 fatal("no head revision in RCS file for %s", cf->file_path); 576 577 if (isnew == 0 && onbranch == 0) 578 d = commit_diff(cf, cf->file_rcs->rf_head, 0); 579 580 if (cf->file_status == FILE_REMOVED) { 581 b = rcs_rev_getbuf(cf->file_rcs, crev, 0); 582 } else if (onbranch == 1) { 583 b = commit_diff(cf, crev, 1); 584 } else { 585 b = cvs_buf_load_fd(cf->fd); 586 } 587 588 if (isnew == 0 && onbranch == 0) { 589 if (rcs_deltatext_set(cf->file_rcs, crev, d) == -1) 590 fatal("cvs_commit_local: failed to set delta"); 591 } 592 593 if (rcs_rev_add(cf->file_rcs, nrev, logmsg, -1, NULL) == -1) 594 fatal("cvs_commit_local: failed to add new revision"); 595 596 if (nrev == RCS_HEAD_REV) 597 nrev = cf->file_rcs->rf_head; 598 599 if (rcs_deltatext_set(cf->file_rcs, nrev, b) == -1) 600 fatal("cvs_commit_local: failed to set new HEAD delta"); 601 602 if (cf->file_status == FILE_REMOVED) { 603 if (rcs_state_set(cf->file_rcs, nrev, RCS_STATE_DEAD) == -1) 604 fatal("cvs_commit_local: failed to set state"); 605 } 606 607 if (cf->file_status == FILE_ADDED && cf->file_ent->ce_opts != NULL) { 608 int cf_kflag; 609 610 cf_kflag = rcs_kflag_get(cf->file_ent->ce_opts + 2); 611 rcs_kwexp_set(cf->file_rcs, cf_kflag); 612 } 613 614 rcs_write(cf->file_rcs); 615 616 if (cf->file_status == FILE_REMOVED) { 617 strlcpy(nbuf, "Removed", sizeof(nbuf)); 618 } else if (cf->file_status == FILE_ADDED) { 619 if (cf->file_rcs->rf_dead == 1) 620 strlcpy(nbuf, "Initial Revision", sizeof(nbuf)); 621 else 622 rcsnum_tostr(nrev, nbuf, sizeof(nbuf)); 623 } else if (cf->file_status == FILE_MODIFIED) { 624 rcsnum_tostr(nrev, nbuf, sizeof(nbuf)); 625 } 626 627 if (verbosity > 1) 628 cvs_printf("new revision: %s\n", nbuf); 629 630 (void)unlink(cf->file_path); 631 (void)close(cf->fd); 632 cf->fd = -1; 633 634 if (cf->file_status != FILE_REMOVED) { 635 cvs_checkout_file(cf, nrev, NULL, CO_COMMIT); 636 } else { 637 entlist = cvs_ent_open(cf->file_wd); 638 cvs_ent_remove(entlist, cf->file_name); 639 640 cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN); 641 642 (void)xsnprintf(attic, MAXPATHLEN, "%s/%s", 643 repo, CVS_PATH_ATTIC); 644 645 if (mkdir(attic, 0755) == -1 && errno != EEXIST) 646 fatal("cvs_commit_local: failed to create Attic"); 647 648 (void)xsnprintf(attic, MAXPATHLEN, "%s/%s/%s%s", repo, 649 CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT); 650 651 if (rename(cf->file_rpath, attic) == -1) 652 fatal("cvs_commit_local: failed to move %s to Attic", 653 cf->file_path); 654 655 if (cvs_server_active == 1) 656 cvs_server_update_entry("Remove-entry", cf); 657 } 658 659 if (verbosity > 1) 660 cvs_printf("done\n"); 661 else { 662 cvs_log(LP_NOTICE, "checking in '%s'; revision %s -> %s", 663 cf->file_path, rbuf, nbuf); 664 } 665 666 if (line_list != NULL) { 667 fi = xcalloc(1, sizeof(*fi)); 668 fi->file_path = xstrdup(cf->file_path); 669 fi->crevstr = xstrdup(rbuf); 670 fi->nrevstr = xstrdup(nbuf); 671 if (tag != NULL) 672 fi->tag_new = xstrdup(tag); 673 TAILQ_INSERT_TAIL(&files_info, fi, flist); 674 } 675 676 switch (cf->file_status) { 677 case FILE_MODIFIED: 678 histtype = CVS_HISTORY_COMMIT_MODIFIED; 679 break; 680 case FILE_ADDED: 681 histtype = CVS_HISTORY_COMMIT_ADDED; 682 break; 683 case FILE_REMOVED: 684 histtype = CVS_HISTORY_COMMIT_REMOVED; 685 break; 686 } 687 688 if (crev != NULL) 689 rcsnum_free(crev); 690 691 cvs_history_add(histtype, cf, NULL); 692 } 693 694 static BUF * 695 commit_diff(struct cvs_file *cf, RCSNUM *rev, int reverse) 696 { 697 int fd1, fd2, f; 698 char *p1, *p2, *p; 699 BUF *b; 700 701 (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir); 702 703 if (cf->file_status == FILE_MODIFIED || 704 cf->file_status == FILE_ADDED) { 705 b = cvs_buf_load_fd(cf->fd); 706 fd1 = cvs_buf_write_stmp(b, p1, NULL); 707 cvs_buf_free(b); 708 } else { 709 fd1 = rcs_rev_write_stmp(cf->file_rcs, rev, p1, 0); 710 } 711 712 (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir); 713 fd2 = rcs_rev_write_stmp(cf->file_rcs, rev, p2, RCS_KWEXP_NONE); 714 715 b = cvs_buf_alloc(128); 716 717 diff_format = D_RCSDIFF; 718 719 if (reverse == 1) { 720 p = p1; 721 p1 = p2; 722 p2 = p; 723 724 f = fd1; 725 fd1 = fd2; 726 fd2 = f; 727 } 728 729 if (cvs_diffreg(p1, p2, fd1, fd2, b) == D_ERROR) 730 fatal("commit_diff: failed to get RCS patch"); 731 732 close(fd1); 733 close(fd2); 734 735 xfree(p1); 736 xfree(p2); 737 738 return (b); 739 } 740 741 static void 742 commit_desc_set(struct cvs_file *cf) 743 { 744 BUF *bp; 745 int fd; 746 char desc_path[MAXPATHLEN], *desc; 747 748 (void)xsnprintf(desc_path, MAXPATHLEN, "%s/%s/%s%s", 749 cf->file_wd, CVS_PATH_CVSDIR, cf->file_name, CVS_DESCR_FILE_EXT); 750 751 if ((fd = open(desc_path, O_RDONLY)) == -1) 752 return; 753 754 bp = cvs_buf_load_fd(fd); 755 cvs_buf_putc(bp, '\0'); 756 desc = cvs_buf_release(bp); 757 758 rcs_desc_set(cf->file_rcs, desc); 759 760 (void)close(fd); 761 (void)cvs_unlink(desc_path); 762 763 xfree(desc); 764 } 765