aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/cvs/cvs/create_adm.c
blob: cceeb772c2a819bf1d1f3ee4694070f65ffbbe5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (c) 1992, Brian Berliner and Jeff Polk
 * Copyright (c) 1989-1992, Brian Berliner
 *
 * You may distribute under the terms of the GNU General Public License as
 * specified in the README file that comes with the CVS 1.4 kit.
 *
 * Create Administration.
 *
 * Creates a CVS administration directory based on the argument repository; the
 * "Entries" file is prefilled from the "initrecord" argument.
 */

#include "cvs.h"

#ifndef lint
static char rcsid[] = "$CVSid: @(#)create_adm.c 1.28 94/09/23 $";
USE(rcsid)
#endif

void
Create_Admin (dir, repository, tag, date)
    char *dir;
    char *repository;
    char *tag;
    char *date;
{
    FILE *fout;
    char *cp;
    char tmp[PATH_MAX];

    if (noexec)
	return;

    if (dir != NULL)
	(void) sprintf (tmp, "%s/%s", dir, CVSADM);
    else
	(void) strcpy (tmp, CVSADM);

    if (isfile (tmp))
	error (1, 0, "there is a version here already");
    else
    {
	if (dir != NULL)
	    (void) sprintf (tmp, "%s/%s", dir, OCVSADM);
	else
	    (void) strcpy (tmp, OCVSADM);

	if (isfile (tmp))
	    error (1, 0, "there is a version here already");
    }

    if (dir != NULL)
	(void) sprintf (tmp, "%s/%s", dir, CVSADM);
    else
	(void) strcpy (tmp, CVSADM);
    make_directory (tmp);

#ifdef CVSADM_ROOT
    /* record the current cvs root for later use */

    Create_Root (dir, CVSroot);
#endif /* CVSADM_ROOT */
    if (dir != NULL)
	(void) sprintf (tmp, "%s/%s", dir, CVSADM_REP);
    else
	(void) strcpy (tmp, CVSADM_REP);
    fout = open_file (tmp, "w+");
    cp = repository;
    strip_path (cp);

#ifdef RELATIVE_REPOS
    /*
     * If the Repository file is to hold a relative path, try to strip off
     * the leading CVSroot argument.
     */
    if (CVSroot != NULL)
    {
	char path[PATH_MAX];

	(void) sprintf (path, "%s/", CVSroot);
	if (strncmp (repository, path, strlen (path)) == 0)
	    cp = repository + strlen (path);
    }
#endif

    if (fprintf (fout, "%s\n", cp) == EOF)
	error (1, errno, "write to %s failed", tmp);
    if (fclose (fout) == EOF)
	error (1, errno, "cannot close %s", tmp);

    /* now, do the Entries file */
    if (dir != NULL)
	(void) sprintf (tmp, "%s/%s", dir, CVSADM_ENT);
    else
	(void) strcpy (tmp, CVSADM_ENT);
    fout = open_file (tmp, "w+");
    if (fclose (fout) == EOF)
	error (1, errno, "cannot close %s", tmp);

    /* Create a new CVS/Tag file */
    WriteTag (dir, tag, date);
}