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