ChangeLog:

Fri Nov 15 13:06:03 1996  Tom Hageman  <tom@basil.icce.rug.nl>

	* checkin.c (Checkin): Backup original of cvswrapped file, and
	restore it in case of no differences due to checkin, or on error.

	* diff.c (diff_fileproc): In printing error messages, use the
	correct filename for which the error occurred.

	* filesubr.c (deep_remove_dir): If necessary, make second pass
	over directory to remove stale NFS handles.
	
	* import.c (update_rcs_file): Compare just checked-out file with
	cvswrapped file, if any, instead of original.
	(add_rev): Work around ci smartness: move cvswrapped file in place
	of original before checkin, and restore original afterward.

*** cvs-1.9/src/%checkin.c	Wed Oct  2 08:03:56 1996
--- cvs-1.9/src/checkin.c	Sun Nov 10 18:02:08 1996
*************** Checkin (type, finfo, rcs, rev, tag, opt
*** 50,57 ****
          if (tocvsPath)
  	{
!             copy_file (tocvsPath, fname);
! 	    if (unlink_file_dir (finfo->file) < 0)
  		if (! existence_error (errno))
! 		    error (1, errno, "cannot remove %s", finfo->fullname);
  	    copy_file (tocvsPath, finfo->file);
  	}
--- 50,59 ----
          if (tocvsPath)
  	{
! 	    /* Backup the current version of the file. */
! 	    if (unlink_file_dir (fname) < 0)
  		if (! existence_error (errno))
! 		    error (1, errno, "cannot remove %s", fname);
! 	    rename_file (finfo->file, fname);
! 	    /* Copy the wrapped file to the current directory then go to work */
  	    copy_file (tocvsPath, finfo->file);
  	}
*************** Checkin (type, finfo, rcs, rev, tag, opt
*** 62,65 ****
--- 64,68 ----
      }
  
+     /* ??? [TRH] do we really go ahead even if noexec is set? */
      switch (RCS_checkin (rcs, NULL, message, rev, 0))
      {
*************** Checkin (type, finfo, rcs, rev, tag, opt
*** 89,94 ****
  
  	    xchmod (finfo->file, 1);
! 	    if (xcmp (finfo->file, fname) == 0)
  	    {
  		rename_file (fname, finfo->file);
  		/* the time was correct, so leave it alone */
--- 92,103 ----
  
  	    xchmod (finfo->file, 1);
! 
! 	    /* [TRH] FIXME: what if noexec? */
! 	    if (xcmp (finfo->file, tocvsPath ? tocvsPath : fname) == 0)
  	    {
+ 		/* Cannot rename directory back over existing file. */
+ 		if (unlink_file_dir (finfo->file) < 0)
+ 		    if (! existence_error (errno))
+ 			error (1, errno, "cannot remove %s", finfo->file);
  		rename_file (fname, finfo->file);
  		/* the time was correct, so leave it alone */
*************** Checkin (type, finfo, rcs, rev, tag, opt
*** 97,108 ****
  	    else
  	    {
! 		if (unlink_file (fname) < 0)
! 		    error (0, errno, "cannot remove %s", fname);
  		/* sync up with the time from the RCS file */
  		set_time = 1;
  	    }
  
- 	    wrap_fromcvs_process_file (finfo->file);
- 
  	    /*
  	     * If we want read-only files, muck the permissions here, before
--- 106,118 ----
  	    else
  	    {
! 		wrap_fromcvs_process_file (finfo->file);
! 
! 		if (unlink_file_dir (fname) < 0)
! 		    if (! existence_error (errno))
! 			error (0, errno, "cannot remove %s", fname);
  		/* sync up with the time from the RCS file */
  		set_time = 1;
  	    }
  
  	    /*
  	     * If we want read-only files, muck the permissions here, before
*************** Checkin (type, finfo, rcs, rev, tag, opt
*** 133,138 ****
--- 143,151 ----
  
  	    if (!noexec)
+ 	    {
+ 		rename_file (fname, finfo->file);
  		error (1, errno, "could not check in %s -- fork failed",
  		       finfo->fullname);
+ 	    }
  	    return (1);
  
*** cvs-1.9/src/%diff.c	Wed Oct  2 08:03:59 1996
--- cvs-1.9/src/diff.c	Fri Nov  8 22:03:08 1996
*************** diff_fileproc (callerdat, finfo)
*** 512,516 ****
  	if (unlink_file_dir (fname) < 0)
  	    if (! existence_error (errno))
! 		error (1, errno, "cannot remove %s", finfo->file);
  	rename_file (finfo->file, fname);
  	/* Copy the wrapped file to the current directory then go to work */
--- 512,516 ----
  	if (unlink_file_dir (fname) < 0)
  	    if (! existence_error (errno))
! 		error (1, errno, "cannot remove %s", fname);
  	rename_file (finfo->file, fname);
  	/* Copy the wrapped file to the current directory then go to work */
*************** diff_fileproc (callerdat, finfo)
*** 610,614 ****
  	rename_file (fname,finfo->file);
  	if (unlink_file (tocvsPath) < 0)
! 	    error (1, errno, "cannot remove %s", finfo->file);
      }
  
--- 610,614 ----
  	rename_file (fname,finfo->file);
  	if (unlink_file (tocvsPath) < 0)
! 	    error (1, errno, "cannot remove %s", tocvsPath);
      }
  
*** cvs-1.9/src/%filesubr.c	Wed Sep 25 16:42:48 1996
--- cvs-1.9/src/filesubr.c	Fri Nov  8 22:21:35 1996
*************** deep_remove_dir (path)
*** 469,474 ****
--- 469,482 ----
      struct dirent *dp;
      char	   buf[PATH_MAX];
+     int		   status;
+     int		   attempt = 2;
  
+ #if 0
      if (rmdir (path) != 0 && (errno == ENOTEMPTY || errno == EEXIST)) 
+ #endif
+     /* This is an attempt to defeat stale .nfsXXXXX handles,
+        as left around by NeXTSTEPs NFS at least. */
+     while ((status = rmdir (path)) != 0 && attempt-- > 0 &&
+ 	   (errno == ENOTEMPTY || errno == EEXIST)) 
      {
  	if ((dirp = opendir (path)) == NULL)
*************** deep_remove_dir (path)
*** 507,515 ****
  	}
  	closedir (dirp);
  	return rmdir (path);
! 	}
  
      /* Was able to remove the directory return 0 */
      return 0;
  }
  
--- 515,528 ----
  	}
  	closedir (dirp);
+ #if 0
  	return rmdir (path);
! #endif
!     }
  
+ #if 0
      /* Was able to remove the directory return 0 */
      return 0;
+ #endif
+     return status;
  }
  
*** cvs-1.9/src/%import.c	Wed Oct  2 08:04:00 1996
--- cvs-1.9/src/import.c	Fri Nov  8 22:26:14 1996
*************** update_rcs_file (message, vfile, vtag, t
*** 532,536 ****
  
  	tocvsPath = wrap_tocvs_process_file (vfile);
! 	different = xcmp (xtmpfile, vfile);
  	if (tocvsPath)
  	    if (unlink_file_dir (tocvsPath) < 0)
--- 532,536 ----
  
  	tocvsPath = wrap_tocvs_process_file (vfile);
! 	different = xcmp (xtmpfile, (tocvsPath ? tocvsPath : vfile));
  	if (tocvsPath)
  	    if (unlink_file_dir (tocvsPath) < 0)
*************** add_rev (message, rcs, vfile, vers)
*** 590,593 ****
--- 590,594 ----
      int locked, status, ierrno;
      char *tocvsPath;
+     char backup[PATH_MAX];
  
      if (noexec)
*************** add_rev (message, rcs, vfile, vers)
*** 629,637 ****
  	}
      }
! 
      status = RCS_checkin (rcs->path, tocvsPath == NULL ? vfile : tocvsPath,
  			  message, vbranch,
  			  (RCS_FLAGS_QUIET
  			   | (use_file_modtime ? RCS_FLAGS_MODTIME : 0)));
      ierrno = errno;
  
--- 630,662 ----
  	}
      }
! #if 0
!     /* [TRH  8-Nov-96] This soes not work for wrapped files since RCS ci
!        is too smart for its own good and refuses to check in the temporary
!        file into the given repository name.  Sigh...
!        So the correct (although cumbersome) way to do it is like in diff.c,
!        by temporary moving the original file out of the way and copying
!        the temporary into its place, and restoring afterwards. */
      status = RCS_checkin (rcs->path, tocvsPath == NULL ? vfile : tocvsPath,
  			  message, vbranch,
  			  (RCS_FLAGS_QUIET
  			   | (use_file_modtime ? RCS_FLAGS_MODTIME : 0)));
+ #endif
+     else /* (tocvsPath != NULL) */
+     {
+ 	/* Backup the current version of the file to ,,filename */
+ 	sprintf(backup,"%s%s", CVSPREFIX, vfile);
+ 	if (unlink_file_dir (backup) < 0)
+ 	    if (! existence_error (errno))
+ 		error (1, errno, "cannot remove %s", backup);
+ 	rename_file (vfile, backup);
+ 	/* XXX should check that rename succeeded... */
+ 	/* Copy the wrapped file to the current directory then go to work */
+ 	copy_file (tocvsPath, vfile);
+     }
+ 
+     status = RCS_checkin (rcs->path, vfile,
+ 			  message, vbranch,
+ 			  (RCS_FLAGS_QUIET
+ 			   | (use_file_modtime ? RCS_FLAGS_MODTIME : 0)));
      ierrno = errno;
  
*************** add_rev (message, rcs, vfile, vers)
*** 639,645 ****
  	rename_file (FILE_HOLDER, vfile);
      else
  	if (unlink_file_dir (tocvsPath) < 0)
  		error (0, errno, "cannot remove %s", tocvsPath);
! 
      if (status)
      {
--- 664,676 ----
  	rename_file (FILE_HOLDER, vfile);
      else
+     {
+ 	if (unlink_file_dir (vfile) < 0)
+ 	    if (! existence_error (errno))
+ 		error (1, errno, "cannot remove %s", vfile);
+ 
+ 	rename_file (backup, vfile);
  	if (unlink_file_dir (tocvsPath) < 0)
  		error (0, errno, "cannot remove %s", tocvsPath);
!     }
      if (status)
      {
*** cvs-1.9/src/%version.c	Sat Oct  5 20:07:38 1996
--- cvs-1.9/src/version.c	Fri Nov  8 22:34:07 1996
***************
*** 13,17 ****
  #include "cvs.h"
  
! char *version_string = "\nConcurrent Versions System (CVS) 1.9";
  
  #ifdef CLIENT_SUPPORT
--- 13,17 ----
  #include "cvs.h"
  
! char *version_string = "\nConcurrent Versions System (CVS) 1.9 [TRH#1]";
  
  #ifdef CLIENT_SUPPORT
