int status = FILE_UC;
try {
// First step: does the private version needs commit ?
File d = new File(file.getParent());
CvsDirectory c = CvsDirectory.getManager(d, props);
if ( c.status(file.getName()) == CVS.FILE_M ) {
String author = pe.getAuthor();
String env [] = { "USER="+author ,
"LOGNAME="+author };
String msg = ((author != null)
? "Published by "+author+" through Jigsaw"
: "Published through Jigsaw");
c.commit(file.getName(), msg, env);
} else if ( debug ) {
System.out.println("PutList: no commit needed on "+
file.getAbsolutePath()+
" st="+c.status(file.getName()));
}
// Second step: publish
File sd = new File(sfile.getParent());
try {
CvsDirectory sc =
CvsDirectory.getManager(sd, props);
String filename = sfile.getName();
int cvs_status = sc.status(filename);
if (debug) {
System.out.println("publishing "+
CvsDirectory.statusToString(cvs_status)+
" file : "+filename);
}
if (cvs_status == CVS.FILE_C) {
//conflict! we try to merge
//create a backup file
File backup = new File(sfile.getParent(), filename+".bak");
try {
org.w3c.util.IO.copy(sfile, backup);
//try to merge
sc.update(filename);
cvs_status = sc.status(filename);
if (cvs_status == CVS.FILE_M) {
//merge done, so commit.
String author = pe.getAuthor();
String env [] = { "USER="+author ,
"LOGNAME="+author };
String msg = ((author != null)
? "Merged by "+author+
" through Jigsaw"
: "Merged through Jigsaw");
sc.commit(filename, msg, env);
//done so delete backup file
backup.delete();
status = FILE_MG;
} else if (cvs_status == CVS.FILE_C) {
//merge failed
sfile.delete();
backup.renameTo(sfile);
status = FILE_CF;
}
} catch (IOException ex) {
ex.printStackTrace();
status = FILE_CF;
}
} else if (cvs_status != CVS.FILE_OK) {
sc.update(filename);
status = FILE_PB;
} else if ( debug ) {
System.out.println("PutList: no update needed on "+
sfile.getAbsolutePath()+
" st="+
CvsDirectory.statusToString(cvs_status));
}
} catch (UncheckedOutException ex) {
// perform a get from root
File root = new File(getRoot().getAbsolutePath());
CvsDirectory sc = CvsDirectory.getManager(root, props);
String fpath = file.getAbsolutePath();
String fspace = getCvsSpace().getAbsolutePath();
String path = fpath.substring(fspace.length()+1);
sc.get(path);
status = FILE_PB;
}
// Last step: remove published entries:
entries.remove(pe.getKey());
// publication time