📄 repos.c
字号:
SVN_ERR_W (svn_io_file_create (this_path, contents, pool),
"Creating pre-commit hook");
} /* end pre-commit hook */
/* Pre-revprop-change hook. */
{
this_path = apr_psprintf (pool, "%s%s",
svn_repos_pre_revprop_change_hook (repos, pool),
SVN_REPOS__HOOK_DESC_EXT);
contents =
"#!/bin/sh"
APR_EOL_STR
APR_EOL_STR
"# PRE-REVPROP-CHANGE HOOK"
APR_EOL_STR
"#"
APR_EOL_STR
"# The pre-revprop-change hook is invoked before a revision property"
APR_EOL_STR
"# is modified. Subversion runs this hook by invoking a program"
APR_EOL_STR
"# (script, executable, binary, etc.) named "
"'"
SVN_REPOS__HOOK_PRE_REVPROP_CHANGE "' (for which"
APR_EOL_STR
"# this file is a template), with the following ordered arguments:"
APR_EOL_STR
"#"
APR_EOL_STR
"# [1] REPOS-PATH (the path to this repository)"
APR_EOL_STR
"# [2] REVISION (the revision being tweaked)"
APR_EOL_STR
"# [3] USER (the username of the person tweaking the property)"
APR_EOL_STR
"# [4] PROPNAME (the property being set on the revision)"
APR_EOL_STR
"#"
APR_EOL_STR
"# [STDIN] PROPVAL ** the property value is passed via STDIN."
APR_EOL_STR
"#"
APR_EOL_STR
"# If the hook program exits with success, the propchange happens; but"
APR_EOL_STR
"# if it exits with failure (non-zero), the propchange doesn't happen."
APR_EOL_STR
"# The hook program can use the 'svnlook' utility to examine the "
APR_EOL_STR
"# existing value of the revision property."
APR_EOL_STR
"#"
APR_EOL_STR
"# WARNING: unlike other hooks, this hook MUST exist for revision"
APR_EOL_STR
"# properties to be changed. If the hook does not exist, Subversion "
APR_EOL_STR
"# will behave as if the hook were present, but failed. The reason"
APR_EOL_STR
"# for this is that revision properties are UNVERSIONED, meaning that"
APR_EOL_STR
"# a successful propchange is destructive; the old value is gone"
APR_EOL_STR
"# forever. We recommend the hook back up the old value somewhere."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Unix system, the normal procedure is to have "
"'"
SVN_REPOS__HOOK_PRE_REVPROP_CHANGE
"'"
APR_EOL_STR
"# invoke other programs to do the real work, though it may do the"
APR_EOL_STR
"# work itself too."
APR_EOL_STR
"#"
APR_EOL_STR
"# Note that"
" '" SVN_REPOS__HOOK_PRE_REVPROP_CHANGE "' "
"must be executable by the user(s) who will"
APR_EOL_STR
"# invoke it (typically the user httpd runs as), and that user must"
APR_EOL_STR
"# have filesystem-level permission to access the repository."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Windows system, you should name the hook program"
APR_EOL_STR
"# '" SVN_REPOS__HOOK_PRE_REVPROP_CHANGE ".bat' or "
"'" SVN_REPOS__HOOK_PRE_REVPROP_CHANGE ".exe',"
APR_EOL_STR
"# but the basic idea is the same."
APR_EOL_STR
"#"
APR_EOL_STR
"# Here is an example hook script, for a Unix /bin/sh interpreter:"
APR_EOL_STR
APR_EOL_STR
"REPOS=\"$1\""
APR_EOL_STR
"REV=\"$2\""
APR_EOL_STR
"USER=\"$3\""
APR_EOL_STR
"PROPNAME=\"$4\""
APR_EOL_STR
APR_EOL_STR
"if [ \"$PROPNAME\" = \"svn:log\" ]; then exit 0; fi"
APR_EOL_STR
"exit 1"
APR_EOL_STR;
SVN_ERR_W (svn_io_file_create (this_path, contents, pool),
"Creating pre-revprop-change hook");
} /* end pre-revprop-change hook */
/* Post-commit hook. */
{
this_path = apr_psprintf (pool, "%s%s",
svn_repos_post_commit_hook (repos, pool),
SVN_REPOS__HOOK_DESC_EXT);
contents =
"#!/bin/sh"
APR_EOL_STR
APR_EOL_STR
"# POST-COMMIT HOOK"
APR_EOL_STR
"#"
APR_EOL_STR
"# The post-commit hook is invoked after a commit. Subversion runs"
APR_EOL_STR
"# this hook by invoking a program (script, executable, binary, etc.)"
APR_EOL_STR
"# named '"
SVN_REPOS__HOOK_POST_COMMIT
"' (for which this file is a template) with the "
APR_EOL_STR
"# following ordered arguments:"
APR_EOL_STR
"#"
APR_EOL_STR
"# [1] REPOS-PATH (the path to this repository)"
APR_EOL_STR
"# [2] REV (the number of the revision just committed)"
APR_EOL_STR
"#"
APR_EOL_STR
"# The default working directory for the invocation is undefined, so"
APR_EOL_STR
"# the program should set one explicitly if it cares."
APR_EOL_STR
"#"
APR_EOL_STR
"# Because the commit has already completed and cannot be undone,"
APR_EOL_STR
"# the exit code of the hook program is ignored. The hook program"
APR_EOL_STR
"# can use the 'svnlook' utility to help it examine the"
APR_EOL_STR
"# newly-committed tree."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Unix system, the normal procedure is to have "
"'"
SVN_REPOS__HOOK_POST_COMMIT
"'"
APR_EOL_STR
"# invoke other programs to do the real work, though it may do the"
APR_EOL_STR
"# work itself too."
APR_EOL_STR
"#"
APR_EOL_STR
"# Note that"
" '" SVN_REPOS__HOOK_POST_COMMIT "' "
"must be executable by the user(s) who will"
APR_EOL_STR
"# invoke it (typically the user httpd runs as), and that user must"
APR_EOL_STR
"# have filesystem-level permission to access the repository."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Windows system, you should name the hook program"
APR_EOL_STR
"# '" SVN_REPOS__HOOK_POST_COMMIT ".bat' or "
"'" SVN_REPOS__HOOK_POST_COMMIT ".exe',"
APR_EOL_STR
"# but the basic idea is the same."
APR_EOL_STR
"# "
APR_EOL_STR
"# Here is an example hook script, for a Unix /bin/sh interpreter:"
APR_EOL_STR
APR_EOL_STR
"REPOS=\"$1\""
APR_EOL_STR
"REV=\"$2\""
APR_EOL_STR
APR_EOL_STR
"commit-email.pl \"$REPOS\" \"$REV\" commit-watchers@example.org"
APR_EOL_STR
"log-commit.py --repository \"$REPOS\" --revision \"$REV\""
APR_EOL_STR;
SVN_ERR_W (svn_io_file_create (this_path, contents, pool),
"Creating post-commit hook");
} /* end post-commit hook */
/* Post-revprop-change hook. */
{
this_path = apr_psprintf (pool, "%s%s",
svn_repos_post_revprop_change_hook (repos, pool),
SVN_REPOS__HOOK_DESC_EXT);
contents =
"#!/bin/sh"
APR_EOL_STR
APR_EOL_STR
"# POST-REVPROP-CHANGE HOOK"
APR_EOL_STR
"#"
APR_EOL_STR
"# The post-revprop-change hook is invoked after a revision property"
APR_EOL_STR
"# has been changed. Subversion runs this hook by invoking a program"
APR_EOL_STR
"# (script, executable, binary, etc.) named '"
SVN_REPOS__HOOK_POST_REVPROP_CHANGE
"'"
APR_EOL_STR
"# (for which this file is a template), with the following ordered"
APR_EOL_STR
"# arguments:"
APR_EOL_STR
"#"
APR_EOL_STR
"# [1] REPOS-PATH (the path to this repository)"
APR_EOL_STR
"# [2] REV (the revision that was tweaked)"
APR_EOL_STR
"# [3] USER (the username of the person tweaking the property)"
APR_EOL_STR
"# [4] PROPNAME (the property that was changed)"
APR_EOL_STR
"#"
APR_EOL_STR
"# Because the propchange has already completed and cannot be undone,"
APR_EOL_STR
"# the exit code of the hook program is ignored. The hook program"
APR_EOL_STR
"# can use the 'svnlook' utility to help it examine the"
APR_EOL_STR
"# new property value."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Unix system, the normal procedure is to have "
"'"
SVN_REPOS__HOOK_POST_REVPROP_CHANGE
"'"
APR_EOL_STR
"# invoke other programs to do the real work, though it may do the"
APR_EOL_STR
"# work itself too."
APR_EOL_STR
"#"
APR_EOL_STR
"# Note that"
" '" SVN_REPOS__HOOK_POST_REVPROP_CHANGE "' "
"must be executable by the user(s) who will"
APR_EOL_STR
"# invoke it (typically the user httpd runs as), and that user must"
APR_EOL_STR
"# have filesystem-level permission to access the repository."
APR_EOL_STR
"#"
APR_EOL_STR
"# On a Windows system, you should name the hook program"
APR_EOL_STR
"# '" SVN_REPOS__HOOK_POST_REVPROP_CHANGE ".bat' or "
"'" SVN_REPOS__HOOK_POST_REVPROP_CHANGE ".exe',"
APR_EOL_STR
"# but the basic idea is the same."
APR_EOL_STR
"# "
APR_EOL_STR
"# Here is an example hook script, for a Unix /bin/sh interpreter:"
APR_EOL_STR
APR_EOL_STR
"REPOS=\"$1\""
APR_EOL_STR
"REV=\"$2\""
APR_EOL_STR
"USER=\"$3\""
APR_EOL_STR
"PROPNAME=\"$4\""
APR_EOL_STR
APR_EOL_STR
"propchange-email.pl \"$REPOS\" \"$REV\" \"$USER\" \"$PROPNAME\" "
"watchers@example.org"
APR_EOL_STR;
SVN_ERR_W (svn_io_file_create (this_path, contents, pool),
"Creating post-revprop-change hook");
} /* end post-revprop-change hook */
return SVN_NO_ERROR;
}
static svn_error_t *
create_conf (svn_repos_t *repos, apr_pool_t *pool)
{
SVN_ERR_W (create_repos_dir (repos->conf_path, pool),
"Creating conf directory");
/* Write a default template for svnserve.conf. */
{
static const char * const svnserve_conf_contents =
"### This file controls the configuration of the svnserve daemon, if you"
APR_EOL_STR
"### use it to allow access to this repository. (If you only allow"
APR_EOL_STR
"### access through http: and/or file: URLs, then this file is"
APR_EOL_STR
"### irrelevant.)"
APR_EOL_STR
APR_EOL_STR
"### Visit http://subversion.tigris.org/ for more information."
APR_EOL_STR
APR_EOL_STR
"# [general]"
APR_EOL_STR
"### These options control access to the repository for unauthenticated"
APR_EOL_STR
"### and authenticated users. Valid values are \"write\", \"read\","
APR_EOL_STR
"### and \"none\". The sample settings below are the defaults."
APR_EOL_STR
"# anon-access = read"
APR_EOL_STR
"# auth-access = write"
APR_EOL_STR
"### The password-db option controls the location of the password"
APR_EOL_STR
"### database file. Unless you specify a path starting with a /,"
APR_EOL_STR
"### the file's location is relative to the conf directory."
APR_EOL_STR
"### The format of the password database is similar to this file."
APR_EOL_STR
"### It contains one section labelled [users]. The name and"
APR_EOL_STR
"### password for each user follow, one account per line. The"
APR_EOL_STR
"### format is"
APR_EOL_STR
"### USERNAME = PASSWORD"
APR_EOL_STR
"### Please note that both the user name and password are case"
APR_EOL_STR
"### sensitive. There is no default for the password file."
APR_EOL_STR
"# password-db = passwd"
APR_EOL_STR
"### This option specifies the authentication realm of the repository."
APR_EOL_STR
"### If two repositories have the same authentication realm, they should"
APR_EOL_STR
"### have the same password database, and vice versa. The default realm"
APR_EOL_STR
"### is repository's uuid."
APR_EOL_STR
"# realm = My First Repository"
APR_EOL_STR;
SVN_ERR_W (svn_io_file_create (svn_repos_svnserve_conf (repos, pool),
svnserve_conf_contents, pool),
"Creating svnserve.conf file");
}
return SVN_NO_ERROR;
}
static void
init_repos_dirs (svn_repos_t *repos, const char *path, apr_pool_t *pool)
{
repos->path = apr_pstrdup (pool, path);
repos->db_path = svn_path_join (path, SVN_REPOS__DB_DIR, pool);
repos->dav_path = svn_path_join (path, SVN_REPOS__DAV_DIR, pool);
repos->conf_path = svn_path_join (path, SVN_REPOS__CONF_DIR, pool);
repos->hook_path = svn_path_join (path, SVN_REPOS__HOOK_DIR, pool);
repos->lock_path = svn_path_join (path, SVN_REPOS__LOCK_DIR, pool);
}
static svn_error_t *
create_repos_structure (svn_repos_t *repos,
const char *path,
apr_pool_t *pool)
{
/* Create the top-level repository directory. */
SVN_ERR_W (create_repos_dir (path, pool),
"Could not create top-level directory");
/* Create the DAV sandbox directory. */
SVN_ERR_W (create_repos_dir (repos->dav_path, pool),
"Creating DAV sandbox dir");
/* Create the lock directory. */
SVN_ERR (create_locks (repos, pool));
/* Create the hooks directory. */
SVN_ERR (create_hooks (repos, pool));
/* Create the conf directory. */
SVN_ERR (create_conf (repos, pool));
/* Write the top-level README file. */
{
const char *readme_file_name
= svn_path_join (path, SVN_REPOS__README, pool);
static const char * const readme_contents =
"This is a Subversion repository; use the 'svnadmin' tool to examine"
APR_EOL_STR
"it. Do not add, delete, or modify files here unless you know how"
APR_EOL_STR
"to avoid corrupting the repository."
APR_EOL_STR
/* ### It would be preferable to conditionalize the mention of
DB_CONFIG below, since it's pointless if this is an FSFS
repository, but we don't currently have an clear API for
determining the fs type. Hence, the conditional is in the
English, not the code :-). */
APR_EOL_STR
"If the directory \""
SVN_REPOS__DB_DIR
"\" contains a Berkeley DB environment,"
APR_EOL_STR
"you may need to tweak the values in \""
SVN_REPOS__DB_DIR
"/DB_CONFIG\" to match the"
APR_EOL_STR
"requirements of your site."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -