version 1.11, 2005/10/08 16:27:41 |
version 1.12, 2005/10/09 14:48:13 |
|
|
#define LOCK_UNLOCK 2 |
#define LOCK_UNLOCK 2 |
|
|
static char * checkin_diff_file(RCSFILE *, RCSNUM *, const char *); |
static char * checkin_diff_file(RCSFILE *, RCSNUM *, const char *); |
static char * checkin_getlogmsg(char *, char *, RCSNUM *); |
static char * checkin_getlogmsg(char *, char *, RCSNUM *, RCSNUM *); |
|
|
void |
void |
checkin_usage(void) |
checkin_usage(void) |
{ |
{ |
fprintf(stderr, |
fprintf(stderr, |
"usage: %s [-jlMNqruV] [-d date | -r rev] [-m msg] [-k mode] " |
"usage: %s [-jlMNquV] [-d date] [-r [rev]] [-m msg] [-k mode] " |
"file ...\n", __progname); |
"file ...\n", __progname); |
} |
} |
|
|
|
|
int |
int |
checkin_main(int argc, char **argv) |
checkin_main(int argc, char **argv) |
{ |
{ |
int i, ch, dflag, flags, lkmode, interactive; |
int i, ch, dflag, flags, lkmode, interactive, rflag; |
mode_t fmode; |
mode_t fmode; |
RCSFILE *file; |
RCSFILE *file; |
RCSNUM *frev; |
RCSNUM *frev, *newrev; |
char fpath[MAXPATHLEN]; |
char fpath[MAXPATHLEN]; |
char *rcs_msg, *rev, *filec, *deltatext, *username; |
char *rcs_msg, *filec, *deltatext, *username; |
BUF *bp; |
BUF *bp; |
|
|
flags = RCS_RDWR; |
flags = RCS_RDWR; |
file = NULL; |
file = NULL; |
rcs_msg = rev = NULL; |
rcs_msg = NULL; |
fmode = lkmode = dflag = verbose = 0; |
newrev = NULL; |
|
fmode = lkmode = dflag = verbose = rflag = 0; |
interactive = 1; |
interactive = 1; |
|
|
if ((username = getlogin()) == NULL) { |
if ((username = getlogin()) == NULL) { |
|
|
case 'u': |
case 'u': |
lkmode = LOCK_UNLOCK; |
lkmode = LOCK_UNLOCK; |
break; |
break; |
|
case 'r': |
|
rflag = 1; |
|
if (optarg != NULL) { |
|
if ((newrev = rcsnum_parse(optarg)) == NULL) { |
|
cvs_log(LP_ERR, "bad revision number"); |
|
exit(1); |
|
} |
|
} |
|
break; |
default: |
default: |
(usage)(); |
(usage)(); |
exit(1); |
exit(1); |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
if (rev == NULL) |
|
frev = file->rf_head; |
|
/* |
|
* If no log message specified, get it interactively. |
|
*/ |
|
if (rcs_msg == NULL) |
|
rcs_msg = checkin_getlogmsg(fpath, argv[i], frev); |
|
|
|
if (cvs_buf_putc(bp, '\0') < 0) |
if (cvs_buf_putc(bp, '\0') < 0) |
exit(1); |
exit(1); |
|
|
filec = cvs_buf_release(bp); |
filec = cvs_buf_release(bp); |
|
|
/* |
/* |
|
* If rev is not specified on the command line, |
|
* assume HEAD. |
|
*/ |
|
frev = file->rf_head; |
|
/* |
|
* If no log message specified, get it interactively. |
|
*/ |
|
if (rcs_msg == NULL && newrev == NULL) |
|
rcs_msg = checkin_getlogmsg(fpath, argv[i], frev, NULL); |
|
else if (rcs_msg == NULL && newrev != NULL) |
|
rcs_msg = checkin_getlogmsg(fpath, argv[i], frev, newrev); |
|
|
|
|
|
/* |
* Remove the lock |
* Remove the lock |
*/ |
*/ |
if (rcs_lock_remove(file, frev) < 0) { |
if (rcs_lock_remove(file, frev) < 0) { |
|
|
/* |
/* |
* Current head revision gets the RCS patch as rd_text |
* Current head revision gets the RCS patch as rd_text |
*/ |
*/ |
if (rcs_deltatext_set(file, file->rf_head, deltatext) == -1) { |
if (rcs_deltatext_set(file, frev, deltatext) == -1) { |
cvs_log(LP_ERR, |
cvs_log(LP_ERR, |
"failed to set new rd_text for head rev"); |
"failed to set new rd_text for head rev"); |
exit (1); |
exit (1); |
|
|
/* |
/* |
* Now add our new revision |
* Now add our new revision |
*/ |
*/ |
if (rcs_rev_add(file, RCS_HEAD_REV, rcs_msg, -1) != 0) { |
if (rcs_rev_add(file, (newrev == NULL ? RCS_HEAD_REV : newrev), |
|
rcs_msg, -1) != 0) { |
cvs_log(LP_ERR, "failed to add new revision"); |
cvs_log(LP_ERR, "failed to add new revision"); |
exit(1); |
exit(1); |
} |
} |
|
|
/* |
/* |
|
* If we are checking in to a non-default (ie user-specified) |
|
* revision, set head to this revision. |
|
*/ |
|
if (newrev != NULL) |
|
rcs_head_set(file, newrev); |
|
|
|
/* |
* New head revision has to contain entire file; |
* New head revision has to contain entire file; |
*/ |
*/ |
if (rcs_deltatext_set(file, frev, filec) == -1) { |
if (rcs_deltatext_set(file, frev, filec) == -1) { |
|
|
/* |
/* |
* Do checkout if -u or -l are specified. |
* Do checkout if -u or -l are specified. |
*/ |
*/ |
if (lkmode != 0) { |
if (lkmode != 0 && !rflag) { |
mode_t mode = 0; |
mode_t mode = 0; |
if ((bp = rcs_getrev(file, frev)) == NULL) { |
if ((bp = rcs_getrev(file, newrev)) == NULL) { |
cvs_log(LP_ERR, "cannot get revision"); |
cvs_log(LP_ERR, "cannot get revision"); |
goto err; |
goto err; |
} |
} |
if (lkmode == LOCK_LOCK) { |
if (lkmode == LOCK_LOCK) { |
mode = 0644; |
mode = 0644; |
if (rcs_lock_add(file, username, frev) < 0) { |
if (rcs_lock_add(file, username, newrev) < 0) { |
if (rcs_errno != RCS_ERR_DUPENT) |
if (rcs_errno != RCS_ERR_DUPENT) |
cvs_log(LP_ERR, |
cvs_log(LP_ERR, |
"failed to lock revision"); |
"failed to lock revision"); |
|
|
* Get log message from user interactively. |
* Get log message from user interactively. |
*/ |
*/ |
static char * |
static char * |
checkin_getlogmsg(char *rcsfile, char *workingfile, RCSNUM *rev) |
checkin_getlogmsg(char *rcsfile, char *workingfile, RCSNUM *rev, RCSNUM *rev2) |
{ |
{ |
char *rcs_msg, buf[128], nrev[16], prev[16]; |
char *rcs_msg, buf[128], nrev[16], prev[16]; |
BUF *logbuf; |
BUF *logbuf; |
|
|
tmprev = rcsnum_alloc(); |
tmprev = rcsnum_alloc(); |
rcsnum_cpy(rev, tmprev, 16); |
rcsnum_cpy(rev, tmprev, 16); |
rcsnum_tostr(tmprev, prev, sizeof(prev)); |
rcsnum_tostr(tmprev, prev, sizeof(prev)); |
rcsnum_tostr(rcsnum_inc(tmprev), nrev, sizeof(nrev)); |
if (rev2 == NULL) |
|
rcsnum_tostr(rcsnum_inc(tmprev), nrev, sizeof(nrev)); |
|
else |
|
rcsnum_tostr(rev2, nrev, sizeof(nrev)); |
rcsnum_free(tmprev); |
rcsnum_free(tmprev); |
|
|
if ((logbuf = cvs_buf_alloc(64, BUF_AUTOEXT)) == NULL) { |
if ((logbuf = cvs_buf_alloc(64, BUF_AUTOEXT)) == NULL) { |