getting control with subversion and xcode

本文介绍如何在MacOSX Server v10.4上安装Subversion版本控制系统,包括配置Apache2.0、安装Subversion及WebSVN,并讲解如何在Xcode中集成Subversion进行项目版本控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Getting Control with Subversion and Xcode

Developers on Mac OS X have a powerful and well-integrated tool to maintain efficient version control of your projects, thanks to the support for Subversion built into Xcode 2. If you don't know about Subversion already, you should. It's an open-source version control system that was developed to extend the functionality provided by CVS, and is particularly well supported in Mac OS X. Using this cutting-edge version control system can help you code more efficiently and effectively, allowing you to focus on what the Mac developer community is famous for: great applications.

Installing Subversion fully on Mac OS X Server v10.4 requires installation of Apache 2.0 and other steps specific to Mac OS X. The installation process detailed here will help ensure that you as a Mac developer have easy access to this valuable tool.

Using Version Control

Version control systems keep track of project versions and store them in an organized, accessible, and space-efficient environment. In most systems, developers check out code from a central repository and subsequently import or commit changes back into the system. If multiple developers make simultaneous changes to code, the version control system merges the versions to ensure that all changes are retained without conflict. The system then requires developers to address detected conflicts manually.

What's New in Subversion

While the current standard in open-source version control on UNIX systems is CVS, Subversion is a relatively new open-source version control system offering many features CVS has yet to implement. It also operates with the same basic command structure as CVS, ensuring a smooth transition for users making a switch.

In version 1.0, Subversion included most current CVS functionality with added support for versioned directories, renames, and metadata. Version 1.1 added support for versioned symbolic links and a new repository format called FSFS. FSFS offers an alternative to Berkeley Database (BDB) implementations, providing more traditional file system access to your repositories, which are stored in ordinary flat files. FSFS has several advantages over BDB, including cross-platform access to repositories, increased stability, increased security, and simpler backup procedures. FSFS has become the file system of choice for Subversion and is the default selection in version 1.2. Version 1.2 also adds support for reserved checkouts (used to lock files that cannot be merged) and full Web-based Distributed Authoring and Versioning (WebDAV) auto-versioning, allowing Subversion to automatically enact commits in the background without user interaction.

Installing Apache 2.0

In this article, we discuss Apache 2.0 on the server side, which requires compilation and configuration. By default, Mac OS X Server v10.4 comes prepackaged with Apache 1.3 setup. To host a networked Subversion repository, you need to use Apache 2.0.

You may notice Mac OS X Server v10.4 comes with Apache 2.0 pre-installed but unconfigured in /opt/apache2. To overcome a potential conflict with Subversion, we will download the latest version of Apache 2.0 and compile the distribution with a couple small changes to meet the needs of both Mac OS X and Subversion.

Note: At the time of this writing, the latest stable version of Apache 2.0 is version 2.0.54.

To compile packages, you must have gcc installed on your system, which is included in Xcode Tools on your Mac OS X Server DVD or is available for download from the ADC Member site (requires login).

Before you compile Apache 2.0, you must set up patches and environment variables for a proper installation. Compiling Apache 2.0 allows you to choose whether to install modules, such as support for BDB.

Note: If you choose to use BDB for your file system, you must install BDB and exclude the --without-berkeley-dbstatements found in configure commands in this document.

To install Apache 2.0 on Mac OS X Server v10.4, complete the following steps:

  1. Open Terminal in Mac OS X, and then extract the package tar xvfz httpd-2.0.54.tar.gz
  2. Go to the newly created directory, and then run the following commands in Terminal:
    	cd httpd-2.0.54
    	export ac_cv_func_poll=no
    
  3. Make the following changes to srclib/apr/network_io/unix/sendrecv.c in the apr_socket_send function:
    • Change:
          do {
              rv = write(sock->socketdes, buf, (*len));
          } while (rv == -1 && errno == EINTR);
      
    • To:
          try_write: do {
              rv = write(sock->socketdes, buf, (*len));
          } while (rv == -1 && errno == EINTR);
      
      (That is, add "try_write:" right before the "do {".)
    • Replace the following else clause (that is, delete these five lines):
            else {
                do {
                    rv = write(sock->socketdes, buf, (*len));
                } while (rv == -1 && errno == EINTR);
            }
    

    with these two lines:

    	else
                   goto try_write;
    
  4. Run configure, run make, and then run sudo make install to set up Apache 2.0 for installation:
    	./configure --enable-mods-shared=most --enable-ssl \
        		--with-mpm=worker --without-berkeley-db
    	make
    	sudo make install
    
  5. Create a directory for mod_dav.h, and copy the module to it using the following Terminal commands:
    	cd /usr/local/apache2
    	mkdir -p modules/dav/main
    	cp include/mod_dav.h modules/dav/main/
    

With these commands, you configure Apache 2.0 to compile on your system, then compile and install the distribution.

Note: If you did not install gcc prior to running the configure command, you will get an error here at step 4. You must use sudo to run the make install command.

Installing Subversion

After you have installed and properly set up Apache 2.0, the Subversion installation process is straightforward. We provide instructions here, highlighted by a configure script with Mac OS X specific parameters.

To install Subversion, complete the following steps:

  1. Download the Subversion source code (not the Mac OS X binaries). 

    Note: At the time of this writing, the latest stable version of Subversion was version 1.2.3 (subversion-1.2.3.tar.gz).
  2. Open Terminal in Mac OS X, and then extract the package.
    tar xvfz subversion-1.2.3.tar.gz
    cd subversion-1.2.3
    
  3. Run the following command to configure the distribution for compilation:
    ./configure --prefix=/usr/local \
        --mandir=/usr/local/share/man --with-ssl \
        --with-apxs=/usr/local/apache2/bin/apxs --with-zlib \
        --enable-swig-bindings=no --without-berkeley-db \
        --with-apr=/usr/local/apache2 \
        --with-apr-util=/usr/local/apache2
    
    Note: If you did not install gcc prior to running configure, you will get an error here.
  4. Run the make command, and then run the sudo make install command.
    make
    sudo make install
    

    Note: You must use sudo to run the make install command.

Subversion executables are installed into /usr/local/bin, which is not in the default path in Mac OS X Server v10.4. To add /usr/local/bin to a user's default path, create a .profile file in your home directory (or simply add the line if you already have a .profile file):

	cd ~
	echo 'export PATH="$PATH:/usr/local/bin"' >> .profile

Configuring Apache 2.0 for Subversion

You must configure Apache 2.0 so that it will not conflict with the active pre-installation of Apache 1.3. Set up Apache 2.0 on port 8080, and set it to run on startup, so that it will be active each time you start Mac OS X Server v10.4.

To configure Apache 2.0 for Subversion, complete the following steps:

  1. Make the following change in /usr/local/apache2/conf/httpd.conf:
    • Change the listen port to 8080:
      #Listen 80
      Listen 8080
      
    • Add the path location for Subversion (SVN):
      <Location /svn>
          DAV svn
          SVNPath /Users/tuser/Code/SVN     # Adjust for your specific path
      </Location>
      
    • Add Subversion modules to the end of the Modules section:
      LoadModule dav_svn_module	modules/mod_dav_svn.so
      LoadModule authz_svn_module	modules/mod_authz_svn.so
      
  2. Run the following command to start Apache:
    sudo /usr/local/apache2/bin/apachectl start
    
  3. Create a StartupItem to start Apache 2.0 on each reboot:
    sudo -s
    mkdir /Library/StartupItems   # This directory might already exist
    ditto /System/Library/StartupItems/Apache /Library/StartupItems/Apache2
    mv /Library/StartupItems/Apache2/Apache /Library/StartupItems/Apache2/Apache2
    defaults write /Library/StartupItems/Apache2/StartupParameters Provides -array "Apache2"
    perl -p -i -e 's/WEBSERVER/APACHE2/g' /Library/StartupItems/Apache2/Apache2
    echo "APACHE2=-YES-" >> /etc/hostconfig
    
  4. Point your browser to http://localhost:8080/svn to browse your Subversion repository.

Installing WebSVN

At WebSVN they offer an easy-to-use Web-based interface to your Subversion repositories. (At the time of this writing, the latest stable version of WebSVN was version 1.61 [WebSVN_161.tar.gz].)

Important: You must have PHP installed and configured as an Apache module for WebSVN to operate. See the ADC document PHP on Mac OS X for details.

To install WebSVN, complete the following steps:

  1. Open Terminal in Mac OS X, and then extract the package.
  2. Move the files to the websvn directory using the following command:
    tar xvfz WebSVN_161.tar.gz
    mkdir /usr/local/apache2/htdocs/websvn
    mv WebSVN/* /usr/local/apache2/htdocs/websvn/.
    
  3. Point your browser to http://localhost:8080/websvn/index.php to browse your Subversion repository with WebSVN.

Xcode and Subversion

Support for Subversion is built into Xcode (version 1.5 and later). However, you must create your Subversion repository and import your project into Subversion on the command line before managing it in Xcode. For detailed instructions on the use of Subversion, see the online book Version Control with Subversion which is endorsed by Subversion's developers.

You need a few basic Subversion commands to get you started as well as commands for using Xcode to interface with your Subversion repository. First, create a new repository in a location of your choosing (we're using/Users/tuser as our home directory and HelloWorld as our project name):

	svnadmin create /Users/tuser/Code/SVN

Next, create the following temporary directories to import into Subversion:

	cd/tmp/tmpsvn 
	mkdir HelloWorld 
	mkdir HelloWorld/trunk 
	mkdir HelloWorld/branches 
	mkdir HelloWorld/tags 

Place your new or existing Xcode project in the /trunk directory of your newly created Subversion project, and import the project into your repository using the following commands:

	cp -r /Users/tuser/Code/Xcode/HelloWorld /tmp/tmpsvn/HelloWorld/trunk/.
	svn import /tmp/tmpsvn/Helloworld file:///Users/tuser/Code/SVN \
    		--message 'Initial HelloWorld Import'

Finally, go into the directory you want to use for your Subversion checkout (this will be your working copy of your project), and check out the project. You can subsequently remove temporary directories created in /tmp. Use the following commands:

	cd /Users/tuser/Code/Projects/
	svn checkout file:///Users/tuser/Code/SVN HelloWorld
	rm -rf /tmp/tmpsvn

You now have two locations for your Xcode project. The SVN directory holds the repository. (Do not edit this data manually.) The Projects directory holds the working copy of your project. (This is where you will edit your source code.)

Now it's time to tell Xcode that you're using Subversion for software control management (SCM). Open your project in Xcode from the newly set-up Projects/HelloWorld directory. Click the Info button on the toolbar to bring up the project information window (see Figure 1).

The main Xcode screen

Figure 1: The Main Xcode Screen

In the project information window shown in Figure 2, select Subversion from the SCM pull-down menu, and then activate the Enable SCM check box.

Information for teh 'hello world' project

Figure 2: Information for the HelloWorld Project

Click Edit to define the Subversion tool path, shown in Figure 3.

Define the Subversion tool path

Figure 3: Define the Subversion Tool Path

Close the project information window and explore the SCM menu in the main Xcode screen (see Figure 4) to perform Subversion commands such as Add to RepositoryCommitRefresh, and Update.

Execute SCM commands from the menu

Figure 4: Execute SCM Commands from the Menu

Figure 5 shows an example of running the Compare With command on a previous version of main.c. You can see a change we made to our HelloWorld program.

Comparing versions of main.c

Figure 5: Comparing Versions of main.c

Conclusion

You are now ready to develop code on Mac OS X Server v10.4 using Subversion for version control from the command line, your Web browser, and Xcode. Three powerful options for accessing Subversion's leading-edge version control constructs give Mac OS X developers the power and flexibility to efficiently develop, edit, and maintain complex projects with multiple contributors.

For More Information

  • For more about Subversion, visit the Subversion home page
  • For more about Apache 2.0, visit the Apache home page

Updated: 2005-12-08

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值