1/*
2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
3 *
4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
5 *                                  and others.
6 *
7 * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
8 * Portions Copyright (C) 1989-1992, Brian Berliner
9 *
10 * You may distribute under the terms of the GNU General Public License as
11 * specified in the README file that comes with the CVS source distribution.
12 *
13 * No Difference
14 *
15 * The user file looks modified judging from its time stamp; however it needn't
16 * be.  No_Difference() finds out whether it is or not. If it is not, it
17 * updates the administration.
18 *
19 * returns 0 if no differences are found and non-zero otherwise
20 */
21
22#include "cvs.h"
23#include <assert.h>
24
25int
26No_Difference (finfo, vers)
27    struct file_info *finfo;
28    Vers_TS *vers;
29{
30    Node *p;
31    int ret;
32    char *ts, *options;
33    int retcode = 0;
34    char *tocvsPath;
35
36    /* If ts_user is "Is-modified", we can only conclude the files are
37       different (since we don't have the file's contents).  */
38    if (vers->ts_user != NULL
39	&& strcmp (vers->ts_user, "Is-modified") == 0)
40	return -1;
41
42    if (!vers->srcfile || !vers->srcfile->path)
43	return (-1);			/* different since we couldn't tell */
44
45#ifdef PRESERVE_PERMISSIONS_SUPPORT
46    /* If special files are in use, then any mismatch of file metadata
47       information also means that the files should be considered different. */
48    if (preserve_perms && special_file_mismatch (finfo, vers->vn_user, NULL))
49	return 1;
50#endif
51
52    if (vers->entdata && vers->entdata->options)
53	options = xstrdup (vers->entdata->options);
54    else
55	options = xstrdup ("");
56
57    tocvsPath = wrap_tocvs_process_file (finfo->file);
58    retcode = RCS_cmp_file( vers->srcfile, vers->vn_user, (char **)NULL,
59                            (char *)NULL, options,
60			    tocvsPath == NULL ? finfo->file : tocvsPath );
61    if (retcode == 0)
62    {
63	/* no difference was found, so fix the entries file */
64	ts = time_stamp (finfo->file);
65	Register (finfo->entries, finfo->file,
66		  vers->vn_user ? vers->vn_user : vers->vn_rcs, ts,
67		  options, vers->tag, vers->date, (char *) 0);
68#ifdef SERVER_SUPPORT
69	if (server_active)
70	{
71	    /* We need to update the entries line on the client side.  */
72	    server_update_entries
73	      (finfo->file, finfo->update_dir, finfo->repository, SERVER_UPDATED);
74	}
75#endif
76	free (ts);
77
78	/* update the entdata pointer in the vers_ts structure */
79	p = findnode (finfo->entries, finfo->file);
80	assert (p);
81	vers->entdata = p->data;
82
83	ret = 0;
84    }
85    else
86	ret = 1;			/* files were really different */
87
88    if (tocvsPath)
89    {
90	/* Need to call unlink myself because the noexec variable
91	 * has been set to 1.  */
92	if (trace)
93	    (void) fprintf (stderr, "%s-> unlink (%s)\n",
94			    CLIENT_SERVER_STR, tocvsPath);
95	if ( CVS_UNLINK (tocvsPath) < 0)
96	    error (0, errno, "could not remove %s", tocvsPath);
97    }
98
99    free (options);
100    return (ret);
101}
102