version 1.3, 2005/09/29 21:30:10 |
version 1.4, 2005/10/04 23:04:33 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
|
|
#include "log.h" |
#include "log.h" |
#include "rcs.h" |
#include "rcs.h" |
|
|
|
|
extern char *__progname; |
extern char *__progname; |
|
|
|
#define LOCK_LOCK 1 |
|
#define LOCK_UNLOCK 2 |
|
|
int |
int |
checkout_main(int argc, char **argv) |
checkout_main(int argc, char **argv) |
{ |
{ |
int i, ch; |
int i, ch; |
RCSNUM *rev; |
int lock; |
|
RCSNUM *frev, *rev; |
RCSFILE *file; |
RCSFILE *file; |
BUF *bp; |
BUF *bp; |
char buf[16]; |
char buf[16]; |
char *s, fpath[MAXPATHLEN]; |
char fpath[MAXPATHLEN]; |
|
char *username; |
|
|
|
lock = 0; |
rev = RCS_HEAD_REV; |
rev = RCS_HEAD_REV; |
while ((ch = getopt(argc, argv, "qr:")) != -1) { |
|
|
if ((username = getlogin()) == NULL) { |
|
cvs_log(LP_ERR, "failed to get username"); |
|
exit (1); |
|
} |
|
|
|
while ((ch = getopt(argc, argv, "l:qr:u:")) != -1) { |
switch (ch) { |
switch (ch) { |
|
case 'l': |
|
if (rev != RCS_HEAD_REV) |
|
cvs_log(LP_WARN, |
|
"redefinition of revision number"); |
|
|
|
if ((rev = rcsnum_parse(optarg)) == NULL) { |
|
cvs_log(LP_ERR, "bad revision number"); |
|
exit (1); |
|
} |
|
|
|
lock = LOCK_LOCK; |
|
break; |
case 'q': |
case 'q': |
verbose = 0; |
verbose = 0; |
break; |
break; |
case 'r': |
case 'r': |
|
if (rev != RCS_HEAD_REV) |
|
cvs_log(LP_WARN, |
|
"redefinition of revision number"); |
|
|
if ((rev = rcsnum_parse(optarg)) == NULL) { |
if ((rev = rcsnum_parse(optarg)) == NULL) { |
cvs_log(LP_ERR, "bad revision number"); |
cvs_log(LP_ERR, "bad revision number"); |
exit(1); |
exit(1); |
} |
} |
|
|
break; |
break; |
|
case 'u': |
|
lock = LOCK_UNLOCK; |
|
if (rev != RCS_HEAD_REV) |
|
cvs_log(LP_WARN, |
|
"redefinition of revision number"); |
|
|
|
if ((rev = rcsnum_parse(optarg)) == NULL) { |
|
cvs_log(LP_ERR, "bad revision number"); |
|
exit (1); |
|
} |
|
|
|
break; |
default: |
default: |
(usage)(); |
(usage)(); |
exit(1); |
exit(1); |
|
|
if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0) |
if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0) |
continue; |
continue; |
|
|
if ((file = rcs_open(fpath, RCS_READ)) == NULL) |
if ((file = rcs_open(fpath, RCS_RDWR)) == NULL) |
continue; |
continue; |
|
|
if ((s = strrchr(fpath, ',')) != NULL) |
if (rev == RCS_HEAD_REV) |
*s = '\0'; |
frev = file->rf_head; |
|
else |
|
frev = rev; |
|
|
if ((bp = rcs_getrev(file, rev)) == NULL) { |
rcsnum_tostr(frev, buf, sizeof(buf)); |
cvs_log(LP_ERR, "cannot find '%s' in %s", |
|
rcsnum_tostr(rev, buf, sizeof(buf)), fpath); |
if ((bp = rcs_getrev(file, frev)) == NULL) { |
|
cvs_log(LP_ERR, "cannot find '%s' in %s", buf, fpath); |
rcs_close(file); |
rcs_close(file); |
continue; |
continue; |
} |
} |
|
|
if (cvs_buf_write(bp, fpath, 0644) < 0) |
if (cvs_buf_write(bp, argv[i], 0644) < 0) { |
cvs_log(LP_ERR, "failed to write revision to file"); |
cvs_log(LP_ERR, "failed to write revision to file"); |
|
cvs_buf_free(bp); |
|
rcs_close(file); |
|
continue; |
|
} |
|
|
cvs_buf_free(bp); |
cvs_buf_free(bp); |
|
|
|
if (lock == LOCK_LOCK) { |
|
if (rcs_lock_add(file, username, frev) < 0) { |
|
if (rcs_errno != RCS_ERR_DUPENT) |
|
cvs_log(LP_ERR, "failed to lock '%s'", buf); |
|
else |
|
cvs_log(LP_WARN, "you already have a lock"); |
|
} else { |
|
if (verbose) |
|
printf("(locked)"); |
|
} |
|
} else if (lock == LOCK_UNLOCK) { |
|
if (rcs_lock_remove(file, frev) < 0) { |
|
if (rcs_errno != RCS_ERR_NOENT) |
|
cvs_log(LP_ERR, |
|
"failed to remove lock '%s'", buf); |
|
} |
|
} |
|
|
rcs_close(file); |
rcs_close(file); |
|
if (verbose) { |
|
printf("revision %s (%s)\n", buf, (lock == LOCK_LOCK) ? |
|
"locked" : "unlocked"); |
|
printf("done\n"); |
|
} |
} |
} |
|
|
if (rev != RCS_HEAD_REV) |
if (rev != RCS_HEAD_REV) |