目录
Version control can be a complex subject, as much art as science, that offers myriad ways of getting stuff done. Throughout this book, you've read of the various Subversion command-line client subcommands and the options that modify their behavior. In this chapter, we'll look into still more ways to customize the way Subversion works for you—setting up the Subversion runtime configuration, using external helper applications, Subversion's interaction with the operating system's configured locale, and so on.
Subversion provides many optional behaviors that can be controlled by the user. Many of these options are of the kind that a user would wish to apply to all Subversion operations. So, rather than forcing users to remember command-line arguments for specifying these options and to use them for every operation they perform, Subversion uses configuration files, segregated into a Subversion configuration area.
The Subversion configuration area is a two-tiered hierarchy of option names and their values. Usually, this boils down to a special directory that contains configuration files (the first tier), which are just text files in standard INI format (with “sections” providing the second tier). These files can be easily edited using your favorite text editor (such as Emacs or vi), and that contain directives read by the client to determine which of several optional behaviors the user prefers.
The first time that the svn
command-line client is executed, it creates a per-user
configuration area. On Unix-like systems, this area appears
as a directory named .subversion
in the
user's home directory. On Win32 systems, Subversion creates a
folder named Subversion
, typically inside
the Application Data
area of the user's
profile directory (which, by the way, is usually a hidden
directory). However, on this platform, the exact location
differs from system to system and is dictated by the Windows
registry.
[47]
We will refer to the per-user configuration area using its Unix
name, .subversion
.
除了用户配置区,Subversion也提供了系统配置区,通过系统配置区,系统管理员可以为某个机器的所有用户建立缺省配置值。注意系统配置区不会规定强制性的策略—每个用户配置区都可以覆盖系统配置区中的配置项,而svn的命令行参数决定了最后的行为。在类Unix的平台上,系统配置区位于/etc/subversion
目录下,在Windows平台上,系统配置区位于Application Data
(再说一次,是由Windows注册表决定的)的Subversion
目录中。与每用户配置区不同,svn不会试图创建系统配置区。
The per-user configuration area currently contains three
files—two configuration files (config
and
servers
), and a README.txt
file, which describes the INI format. At the time of their
creation, the files contain default values for each of the
supported Subversion options, mostly commented out and grouped
with textual descriptions about how the values for the key
affect Subversion's behavior. To change a certain behavior,
you need only to load the appropriate configuration file into
a text editor, and to modify the desired option's value. If at
any time you wish to have the default configuration settings
restored, you can simply remove (or rename) your configuration
directory and then run some innocuous svn
command, such as svn --version. A new
configuration directory with the default contents will be
created.
用户配置区也缓存了认证信息,auth
目录下的子目录中缓存了一些Subversion支持的各种认证方法的信息,这个目录需要相应的用户权限才可以访问。
除了基于INI文件的配置区,运行在Windows平台的Subversion客户端也可以使用Windows注册表来保存配置数据。注册表中保存的选项名称和值的含义与INI文件中相同,“file/section”在注册表中表现为注册表键树的层级,使得双层结构得以保留下来。
Subversion的系统配置值保存在键HKEY_LOCAL_MACHINE\Software\Tigris.org\Subversion
下。举个例子,global-ignores
选项位于config
文件的miscellany
小节,在Windows注册表中,则位于HKEY_LOCAL_MACHINE\Software\Tigris.org\Subversion\Config\Miscellany\global-ignores
。用户配置值存放在HKEY_CURRENT_USER\Software\Tigris.org\Subversion
下。
基于注册表的配置项在基于文件的配置项之前解析,所以其配置项的值会被配置文件中相同配置项的值覆盖,换句话说,在Windows系统下这样查找配置信息;低位的位置优先于高位的位置:
命令行选项
用户INI配置文件
用户注册表值
系统INI配置文件
系统注册表值
Also, the Windows Registry doesn't really support the
notion of something being “commented out.”
However, Subversion will ignore any option key whose name
begins with a hash (#
) character. This
allows you to effectively comment out a Subversion option
without deleting the entire key from the Registry, obviously
simplifying the process of restoring that option.
The svn command-line client never
attempts to write to the Windows Registry and will not attempt
to create a default configuration area there. You can create
the keys you need using the REGEDIT
program. Alternatively, you can create a
.reg
file (such as the one in 例 7.1 “Sample registration entries (.reg) file.”), and
then double-click on that file's icon in the Explorer shell,
which will cause the data to be merged into your
registry.
例 7.1. Sample registration entries (.reg) file.
REGEDIT4 [HKEY_LOCAL_MACHINE\Software\Tigris.org\Subversion\Servers\groups] [HKEY_LOCAL_MACHINE\Software\Tigris.org\Subversion\Servers\global] "#http-proxy-host"="" "#http-proxy-port"="" "#http-proxy-username"="" "#http-proxy-password"="" "#http-proxy-exceptions"="" "#http-timeout"="0" "#http-compression"="yes" "#neon-debug-mask"="" "#ssl-authority-files"="" "#ssl-trust-default-ca"="" "#ssl-client-cert-file"="" "#ssl-client-cert-password"="" [HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\auth] "#store-passwords"="yes" "#store-auth-creds"="yes" [HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\helpers] "#editor-cmd"="notepad" "#diff-cmd"="" "#diff3-cmd"="" "#diff3-has-program-arg"="" [HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\tunnels] [HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\miscellany] "#global-ignores"="*.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store" "#log-encoding"="" "#use-commit-times"="" "#no-unlock"="" "#enable-auto-props"="" [HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\auto-props]
The previous example shows the contents of a
.reg
file, which contains some of the most
commonly used configuration options and their default values.
Note the presence of both system-wide (for network
proxy-related options) and per-user settings (editor programs
and password storage, among others). Also note that all the
options are effectively commented out. You need only to
remove the hash (#
) character from the
beginning of the option names and set the values as you
desire.
In this section, we will discuss the specific runtime configuration options that are currently supported by Subversion.
The servers
file contains
Subversion configuration options related to the network
layers. There are two special section names in this
file—groups
and
global
. The groups
section is essentially a cross-reference table. The keys in
this section are the names of other sections in the file;
their values are globs—textual
tokens that possibly contain wildcard
characters—that are compared against the hostnames of
the machine to which Subversion requests are sent.
[groups] beanie-babies = *.red-bean.com collabnet = svn.collab.net [beanie-babies] … [collabnet] …
When Subversion is used over a network, it attempts to
match the name of the server it is trying to reach with a
group name under the groups
section. If
a match is made, Subversion then looks for a section in the
servers
file whose name is the matched
group's name. From that section, it reads the actual network
configuration settings.
The global
section contains the
settings that are meant for all of the servers not matched
by one of the globs under the groups
section. The options available in this section are
exactly the same as those that are valid for the other server
sections in the file (except, of course, the special
groups
section), and are as
follows:
http-proxy-exceptions
This specifies a comma-separated list of patterns for repository hostnames that should be accessed directly, without using the proxy machine. The pattern syntax is the same as is used in the Unix shell for filenames. A repository hostname matching any of these patterns will not be proxied.
http-proxy-host
代理服务器的详细主机名,是HTTP为基础的Subversion请求必须通过的,缺省值为空,意味着Subversion不会尝试通过代理服务器进行HTTP请求,而会尝试直接连接目标机器。
http-proxy-port
代理服务器的详细端口,缺省值为空。
http-proxy-username
代理服务器的用户名,缺省值为空。
http-proxy-password
代理服务器的密码,缺省为空。
http-timeout
等待服务器响应的时间,以秒为单位,如果你的网络速度较慢,导致Subversion的操作超时,你可以加大这个数值,缺省值是0
,意思是让HTTP库Neon使用自己的缺省值。
http-compression
这说明是否在与设置好DAV的服务器通讯时使用网络压缩请求,缺省值是yes
(尽管只有在这个功能编译到网络层时压缩才会有效),设置no
来关闭压缩,如调试网络传输时。
http-library
Subversion provides a pair of repository access
modules that understand its WebDAV network protocol.
The original one, which shipped with Subversion 1.0, is
libsvn_ra_neon
(though back then it
was called libsvn_ra_dav
). Newer
Subversion versions also provide
libsvn_ra_serf
, which uses a
different underlying implementation and aims to
support some of the newer HTTP concepts.
At this point, libsvn_ra_serf
is still considered experimental, though it appears to
work in the common cases quite well. To encourage
experimentation, Subversion provides the
http-library
runtime configuration
option to allow users to specify (generally, or in a
per-server-group fashion) which WebDAV access module
they'd prefer to use—neon
or
serf
.
http-auth-types
This option is a semicolon-delimited list of
authentication types supported by the Neon-based
WebDAV repository access modules. Valid members of
this list are basic
,
digest
, and
negotiate
.
neon-debug-mask
只是一个整形的掩码,底层的HTTP库Neon用来选择产生调试的输出,缺省值是0
,意思是关闭所有的调试输出,关于Subversion使用Neon的详细信息,见第 8 章 嵌入Subversion。
ssl-authority-files
这是一个分号分割的路径和文件列表,这些文件包含了Subversion客户端在用HTTPS访问时可以接受的认证授权(或者CA)证书。
ssl-trust-default-ca
如果你希望Subversion可以自动相信OpenSSL携带的缺省的CA,可以设置为yes
。
ssl-client-cert-file
如果一个主机(或是一些主机)需要一个SSL客户端证书,你会收到一个提示说需要证书的路径。通过设置这个路径你的Subversion客户端可以自动找到你的证书而不会打扰你。没有标准的存放位置;Subversion会从任何你指定的路径得到这个文件。
ssl-client-cert-password
如果你的SSL客户端证书文件是用密码加密的,Subversion会在每次使用证书时请你输入密码,如果你发现这很讨厌(并且不介意把密码存放在servers
文件中),你可以设置这个参数为证书的密码,这样就不会再收到密码输入提示了。
The config
file contains the rest
of the currently available Subversion runtime
options—those not related to networking. There are
only a few options in use as of this writing, but they are
again grouped into sections in expectation of future
additions.
The auth
section contains settings
related to Subversion's authentication and authorization
against the repository. It contains the following:
store-passwords
这告诉Subversion是否缓存服务器认证要求时用户提供的密码,缺省值是yes
。设置为no
可以关闭在存盘的密码缓存,你可以通过svn的--no-auth-cache
命令行参数(那些支持这个参数的子命令)来覆盖这个设置,详细信息请见“客户端凭证缓存”一节。
store-auth-creds
这个设置与store-passwords
相似,不过设置了这个选项将会保存所有认证信息,如用户名、密码、服务器证书,以及其他任何类型的可以缓存的凭证。
helpers
小节控制完成Subversion任务的外部程序,正确的选项包括:
editor-cmd
This specifies the program Subversion will use to query the user for certain types of textual metadata or when interactively resolving conflicts. See “Using External Editors”一节 for more details on using external text editors with Subversion.
diff-cmd
This specifies the absolute path of a differencing program, used when Subversion generates “diff” output (such as when using the svn diff command). By default, Subversion uses an internal differencing library—setting this option will cause it to perform this task using an external program. See “Using External Differencing and Merge Tools”一节 for more details on using such programs.
diff3-cmd
This specifies the absolute path of a three-way differencing program. Subversion uses this program to merge changes made by the user with those received from the repository. By default, Subversion uses an internal differencing library—setting this option will cause it to perform this task using an external program. See “Using External Differencing and Merge Tools”一节 for more details on using such programs.
diff3-has-program-arg
如果diff3-cmd
选项设置的程序接受一个--diff-program
命令行参数,这个标记必须设置为true
。
merge-tool-cmd
This specifies the program that Subversion will use to perform three-way merge operations on your versioned files. See “Using External Differencing and Merge Tools”一节 for more details on using such programs.
tunnels
小节允许你定义一个svnserve和svn://
客户端连接使用的管道模式,更多细节见“SSH 隧道”一节。
miscellany
小节是一些没法归到别处的选项。 [48]在本小节,你会找到:
global-ignores
When running the svn status
command, Subversion lists unversioned files and
directories along with the versioned ones, annotating
them with a ?
character (see “查看你的修改概况”一节). Sometimes, it can
be annoying to see uninteresting, unversioned
items—for example, object files that result from
a program's compilation—in this display. The
global-ignores
option is a list of
whitespace-delimited globs that describe the names of
files and directories that Subversion should not
display unless they are versioned. The default value
is *.o *.lo *.la #*# .*.rej *.rej .*~ *~
.#* .DS_Store
.
As well as svn status, the
svn add and svn import
commands also ignore files that match the list
when they are scanning a directory. You can override this
behavior for a single instance of any of these commands
by explicitly specifying the filename, or by using
the --no-ignore
command-line flag.
For information on more fine-grained control of ignored items, see “忽略未版本控制的条目”一节.
enable-auto-props
This instructs Subversion to automatically set
properties on newly added or imported files. The
default value is no
, so set this to
yes
to enable this feature.
The auto-props
section of this file
specifies which properties are to be set on which files.
log-encoding
This variable sets the default character set
encoding for commit log messages. It's a permanent
form of the --encoding
option (see
“svn选项”一节). The Subversion
repository stores log messages in UTF-8 and assumes
that your log message is written using your operating
system's native locale. You should specify a
different encoding if your commit messages are written
in any other encoding.
use-commit-times
通常你的工作拷贝文件会有最后一次被进程访问的时间戳,不管是你自己的编辑器还是用svn子命令。这通常对人们开发软件提供了便利,因为编译系统通常会通过查看时间戳来决定那些文件需要重新编译。
在其他情形,有时候如果工作拷贝的文件时间戳反映了上一次在版本库中更改的时间会非常好,svn export命令会一直放置这些“上次提交的时间戳”放到它创建的目录树。通过设置这个config参数为yes
,svn checkout、svn update、 svn switch和svn revert命令也会为它们操作的文件设置上次提交的时间戳。
mime-types-file
This option, new to Subversion 1.5, specifies the
path of a MIME types mapping file, such as the
mime.types
file provided by the
Apache HTTP Server. Subversion uses this file to
assign MIME types to newly added or imported files.
See “自动设置属性”一节 and
“文件内容类型”一节 for more about Subversion's detection and use of
file content types.
preserved-conflict-file-exts
The value of this option is a space-delimited list of file extensions that Subversion should preserve when generating conflict filenames. By default, the list is empty. This option is new to Subversion 1.5.
When Subversion detects conflicting file content
changes, it defers resolution of that conflict to the
user. To assist in the resolution, Subversion keeps
pristine copies of the various competing versions of
the file in the working copy. By default, those
conflict files have names constructed by appending to
the original filename a custom extension such as
.mine
or
.
(where REV
REV
is a revision
number). A mild annoyance with this naming scheme is
that on operating systems where a file's extension
determines the default application used to open and
edit that file, appending a custom extension prevents
the file from being easily opened by its native
application. For example, if the file
ReleaseNotes.pdf
was conflicted,
the conflict files might be named
ReleaseNotes.pdf.mine
or
ReleaseNotes.pdf.r4231
. While
your system might be configured to use Adobe's Acrobat
Reader to open files whose extensions are
.pdf
, there probably isn't an
application configured on your system to open all
files whose extensions are
.r4231
.
You can fix this annoyance by using this
configuration option, though. For files with one of
the specified extensions, Subversion will append to
the conflict file names the custom extension just as
before, but then also re-append the file's original
extension. Using the previous example, and assuming
that pdf
is one of the extensions
configured in this list thereof, the conflict files
generated for ReleaseNotes.pdf
would instead be named
ReleaseNotes.pdf.mine.pdf
and
ReleaseNotes.pdf.r4231.pdf
.
Because each of these files end in
.pdf
, the correct default
application will be used to view them.
interactive-conflicts
This is a boolean option that specifies whether
Subversion should try to resolve conflicts
interactively. If its value is yes
(which is the default value), Subversion will prompt
the user for how to handle conflicts in the manner
demonstrated in “解决冲突(合并别人的修改)”一节. Otherwise, it will simply flag the conflict and
continue its operation, postponing resolution to a later
time.
no-unlock
This boolean option corresponds to svn
commit's --no-unlock
option, which tells Subversion not to release locks on
files you've just committed. If this runtime option
is set to yes
, Subversion will
never release locks automatically, leaving you to run
svn unlock explicitly. It defaults
to no
.
The auto-props
section controls
the Subversion client's ability to automatically set
properties on files when they are added or imported.
It contains any number of key-value pairs in the
format PATTERN = PROPNAME=PROPVALUE
,
where PATTERN
is a file pattern
that matches a set of filenames and the rest of the
line is the property and its value. Multiple matches
on a file will result in multiple propsets for that
file; however, there is no guarantee that auto-props
will be applied in the order in which they are listed
in the config file, so you can't have one rule
“override” another. You can find several
examples of auto-props usage in the
config
file. Lastly, don't
forget to set enable-auto-props
to
yes
in the miscellany
section if you want to enable auto-props.