xref: /dflybsd-src/contrib/cvs-1.12/src/no_diff.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino  * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
386d7f5d3SJohn Marino  *
486d7f5d3SJohn Marino  * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
586d7f5d3SJohn Marino  *                                  and others.
686d7f5d3SJohn Marino  *
786d7f5d3SJohn Marino  * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
886d7f5d3SJohn Marino  * Portions Copyright (C) 1989-1992, Brian Berliner
986d7f5d3SJohn Marino  *
1086d7f5d3SJohn Marino  * You may distribute under the terms of the GNU General Public License as
1186d7f5d3SJohn Marino  * specified in the README file that comes with the CVS source distribution.
1286d7f5d3SJohn Marino  *
1386d7f5d3SJohn Marino  * No Difference
1486d7f5d3SJohn Marino  *
1586d7f5d3SJohn Marino  * The user file looks modified judging from its time stamp; however it needn't
1686d7f5d3SJohn Marino  * be.  No_Difference() finds out whether it is or not. If it is not, it
1786d7f5d3SJohn Marino  * updates the administration.
1886d7f5d3SJohn Marino  *
1986d7f5d3SJohn Marino  * returns 0 if no differences are found and non-zero otherwise
2086d7f5d3SJohn Marino  */
2186d7f5d3SJohn Marino 
2286d7f5d3SJohn Marino #include "cvs.h"
2386d7f5d3SJohn Marino #include <assert.h>
2486d7f5d3SJohn Marino 
2586d7f5d3SJohn Marino int
No_Difference(struct file_info * finfo,Vers_TS * vers)2686d7f5d3SJohn Marino No_Difference (struct file_info *finfo, Vers_TS *vers)
2786d7f5d3SJohn Marino {
2886d7f5d3SJohn Marino     Node *p;
2986d7f5d3SJohn Marino     int ret;
3086d7f5d3SJohn Marino     char *ts, *options;
3186d7f5d3SJohn Marino     int retcode = 0;
3286d7f5d3SJohn Marino     char *tocvsPath;
3386d7f5d3SJohn Marino 
3486d7f5d3SJohn Marino     /* If ts_user is "Is-modified", we can only conclude the files are
3586d7f5d3SJohn Marino        different (since we don't have the file's contents).  */
3686d7f5d3SJohn Marino     if (vers->ts_user != NULL
3786d7f5d3SJohn Marino 	&& strcmp (vers->ts_user, "Is-modified") == 0)
3886d7f5d3SJohn Marino 	return -1;
3986d7f5d3SJohn Marino 
4086d7f5d3SJohn Marino     if (!vers->srcfile || !vers->srcfile->path)
4186d7f5d3SJohn Marino 	return (-1);			/* different since we couldn't tell */
4286d7f5d3SJohn Marino 
4386d7f5d3SJohn Marino #ifdef PRESERVE_PERMISSIONS_SUPPORT
4486d7f5d3SJohn Marino     /* If special files are in use, then any mismatch of file metadata
4586d7f5d3SJohn Marino        information also means that the files should be considered different. */
4686d7f5d3SJohn Marino     if (preserve_perms && special_file_mismatch (finfo, vers->vn_user, NULL))
4786d7f5d3SJohn Marino 	return 1;
4886d7f5d3SJohn Marino #endif
4986d7f5d3SJohn Marino 
5086d7f5d3SJohn Marino     if (vers->entdata && vers->entdata->options)
5186d7f5d3SJohn Marino 	options = xstrdup (vers->entdata->options);
5286d7f5d3SJohn Marino     else
5386d7f5d3SJohn Marino 	options = xstrdup ("");
5486d7f5d3SJohn Marino 
5586d7f5d3SJohn Marino     tocvsPath = wrap_tocvs_process_file (finfo->file);
5686d7f5d3SJohn Marino     retcode = RCS_cmp_file (vers->srcfile, vers->vn_user, NULL, NULL, options,
5786d7f5d3SJohn Marino 			    tocvsPath == NULL ? finfo->file : tocvsPath);
5886d7f5d3SJohn Marino     if (retcode == 0)
5986d7f5d3SJohn Marino     {
6086d7f5d3SJohn Marino 	/* no difference was found, so fix the entries file */
6186d7f5d3SJohn Marino 	ts = time_stamp (finfo->file);
6286d7f5d3SJohn Marino 	Register (finfo->entries, finfo->file,
6386d7f5d3SJohn Marino 		  vers->vn_user ? vers->vn_user : vers->vn_rcs, ts,
6486d7f5d3SJohn Marino 		  options, vers->tag, vers->date, NULL);
6586d7f5d3SJohn Marino #ifdef SERVER_SUPPORT
6686d7f5d3SJohn Marino 	if (server_active)
6786d7f5d3SJohn Marino 	{
6886d7f5d3SJohn Marino 	    /* We need to update the entries line on the client side.  */
6986d7f5d3SJohn Marino 	    server_update_entries (finfo->file, finfo->update_dir,
7086d7f5d3SJohn Marino 				   finfo->repository, SERVER_UPDATED);
7186d7f5d3SJohn Marino 	}
7286d7f5d3SJohn Marino #endif
7386d7f5d3SJohn Marino 	free (ts);
7486d7f5d3SJohn Marino 
7586d7f5d3SJohn Marino 	/* update the entdata pointer in the vers_ts structure */
7686d7f5d3SJohn Marino 	p = findnode (finfo->entries, finfo->file);
7786d7f5d3SJohn Marino 	assert (p);
7886d7f5d3SJohn Marino 	vers->entdata = p->data;
7986d7f5d3SJohn Marino 
8086d7f5d3SJohn Marino 	ret = 0;
8186d7f5d3SJohn Marino     }
8286d7f5d3SJohn Marino     else
8386d7f5d3SJohn Marino 	ret = 1;			/* files were really different */
8486d7f5d3SJohn Marino 
8586d7f5d3SJohn Marino     if (tocvsPath)
8686d7f5d3SJohn Marino     {
8786d7f5d3SJohn Marino 	/* Need to call unlink myself because the noexec variable
8886d7f5d3SJohn Marino 	 * has been set to 1.  */
8986d7f5d3SJohn Marino 	TRACE (TRACE_FUNCTION, "unlink (%s)", tocvsPath);
9086d7f5d3SJohn Marino 	if ( CVS_UNLINK (tocvsPath) < 0)
9186d7f5d3SJohn Marino 	    error (0, errno, "could not remove %s", tocvsPath);
9286d7f5d3SJohn Marino     }
9386d7f5d3SJohn Marino 
9486d7f5d3SJohn Marino     free (options);
9586d7f5d3SJohn Marino     return ret;
9686d7f5d3SJohn Marino }
97