SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Questions about Version Control

    I'm a long time browser of SitePoint and an avid reader of its newsletters, but I did not realise there was such a huge PHP community here. Other forums with large PHP communities don't tend to focus on PHP primarily, whereas I know for a fact that SitePoint is heavily PHP-orientated. So I've registered. Hopefully this will be an educational experience.

    I am currently developing a browser game written in PHP with a MySQL database. Right now, I've just got the application files on my computer, with a remote version on my server for testing/running the software, and I edit the PHP files with phpDesigner 2007 Pro. So far, things have been fine. I've developed other applications in the same way with no bother, and made vBulletin plugins in the past with this setup. I've not dipped my feet into version control, though I did try running Subversion on my computer a few months ago, to little avail.

    Recently, though, I decided that at one stage or another, I would want to convert many aspects of the application to use different methods. Specifically, as a seasoned unofficial vBulletin developer, I have used way too many eval() functions. I want to go through my application and replace or rewrite sections to make use of strtr() instead, which in my benchmarking appears to be roughly 10 times faster than eval(). As a side project, I would also like to try fully OOP-ising the program at one stage or another. Currently I have three levels of classes - one main class, in which all other classes reside as subclasses (there are no functions within Main yet - though I do plan on adding some cache functions later). These subclasses include ones for handling the database interaction, user input, user information (username, usergroup, access permissions, etc.), and various classes specific to the functioning of the game. The final level has a database explain subclass which extends the main database class for debugging purposes.

    My questions are as follows:

    1. Is it possible with either CVS or SVN (or any other system) to maintain multiple branches of the same program, one being the main program which will eventually get released, one being an experimental program using strtr() in place of eval() but otherwise identical to the first, and a final one using almost entirely different, object oriented code? So for instance, if I were to edit the database class, would CVS or SVN be able to change this class in both the eval() and strtr() versions of the program without overwriting one of them with whichever version of the program had the edits made to it?

    2. Is it possible to configure CVS/SVN/other to allow web access to its physical copies of the program files? I.e. when I edit my local files and my IDE sends the server whatever edits are to be made, can the version controller make these edits to files which are available to the outside world? The reason I ask is because I would like to be able to test my edits on the remote copy of the files using a browser as soon as I submit the edits, rather than running whatever commands are required to produce a 'release' and move it to a web-accessable directory.


    Thanks for your time.

  2. #2
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can only give you an answer for SVN:

    1. yes, branches are supported out of the box. Besides the SVN book, Tags & Branches basics article can also be useful.

    2. not sure what you meant by "test my edits", but if what you need is a source code browser, then setting up SVN on Apache is quite easy.

    If you meant that you want the code to go live after commit, you'd have to install a scheduled update/export from the repository. This goes probably for any version control software out there, you probably can't use the source repository as the the live-and-running code, or at least isn't wise to do so. In SVN, you could create a post-commit hook that could do the update, but I haven't had any experience with it, so I can't tell you more.

    br

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    Regarding branches - what is the general concept behind them? How does the version control system distinguish between code I want to keep the same in all versions and code I want to keep different?

    I meant that I want the code to go live as soon as I commit it, yes. Does anyone know of in-built support for this in any version control software out there, or of any easy ways of adding this functionality to one?

  4. #4
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Both CVS and SVN support tagging and branching. They also support embedding sub projects, although this is more complete with SVN. CVS has some niggles, and is gradually being phased out by SVN. In particular it handled binary files badly, and renaming a directory in CVS is horrific.

    Branches and tags are a convention in SVN, whereas in CVS they are explicit. This makes SVN a little harder to set up initially.

    Quote Originally Posted by Seantyr View Post
    Regarding branches - what is the general concept behind them? How does the version control system distinguish between code I want to keep the same in all versions and code I want to keep different?
    Each version is a diff from a previous version. Merging is simply applying all the diffs from the last branch point into the stream you are merging with.

    Quote Originally Posted by Seantyr View Post
    I meant that I want the code to go live as soon as I commit it, yes. Does anyone know of in-built support for this in any version control software out there, or of any easy ways of adding this functionality to one?
    You really don't want to do this .

    More acceptable is to release a bunch of tags (or copies in a particular folder in SVN). Usually a nightly build is sufficient. Look at some of the continuous integraton tools if it isn't.

    If you just want to view the effects of the code, why not do it from within your sandbox. You should set up your development machine as near as possible to the live environment anyway.

    I would also add automatic test runs into a commit hook. Certainly you want to run your tests as part of deployment.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Seantyr View Post
    1. Is it possible with either CVS or SVN (or any other system) to maintain multiple branches of the same program, one being the main program which will eventually get released, one being an experimental program using strtr() in place of eval() but otherwise identical to the first, and a final one using almost entirely different, object oriented code? So for instance, if I were to edit the database class, would CVS or SVN be able to change this class in both the eval() and strtr() versions of the program without overwriting one of them with whichever version of the program had the edits made to it?
    You can make a branch, which is a copy of (part of) the repository. The main strain is called the trunk. When you change something in the branch, you can merge the changes down to the trunk. You can have multiple branches, if you're working in different directions at once. There are some limitations though. If one of your branches makes massive changes to the code (Such as refactoring procedural scripts into objects), the other branches probably can't merge correctly. Because of this, you generally won't use a branch to refactor the code, but rather to add new behaviour, when you don't want to lock the trunk in. If for example, you want to make a release (called a tag in SVN terminology) once a month, and you're going to add a feature, which you estimate will take three months, you would do that in a branch, so you can keep releasing the trunk, without getting unfinished work out. Once the work in the branch is completed, you can merge all changes down to the trunk.

  6. #6
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft View Post
    You really don't want to do this .

    More acceptable is to release a bunch of tags (or copies in a particular folder in SVN). Usually a nightly build is sufficient. Look at some of the continuous integraton tools if it isn't.
    Thing is, the database for the game is on the server where I want to set up the CVS or SVN. I have other people working on the game; not on the development side, but using tools I have created to let them tinker settings within the game to make it more playable (through an administration section in the game, basically).

    So what you are saying is that it is better to update the web-viewable version of the software manually once a feature has been implemented (or via a nightly build) and tested fully on my own development machine? Is it possible to configure SVN or CVS to 'build a nightly' in a web-accessable directory that doesn't change, i.e. the previous night's code gets overwritten with the new night's code? I don't want to try to have to explain to these other people working on the game that they have to update their bookmarks every night to reflect new directories.

    Quote Originally Posted by lastcraft View Post
    Each version is a diff from a previous version. Merging is simply applying all the diffs from the last branch point into the stream you are merging with.
    I understand. That makes it sound very simple, actually. I guess my idea of making a tag as soon as I made a change to the code would be quite inefficient too, since the version controller would need to read every diff involved in the program and create a copy.

    Quote Originally Posted by kyberfabrikken
    You can make a branch, which is a copy of (part of) the repository. The main strain is called the trunk. When you change something in the branch, you can merge the changes down to the trunk. You can have multiple branches, if you're working in different directions at once. There are some limitations though. If one of your branches makes massive changes to the code (Such as refactoring procedural scripts into objects), the other branches probably can't merge correctly. Because of this, you generally won't use a branch to refactor the code, but rather to add new behaviour, when you don't want to lock the trunk in. If for example, you want to make a release (called a tag in SVN terminology) once a month, and you're going to add a feature, which you estimate will take three months, you would do that in a branch, so you can keep releasing the trunk, without getting unfinished work out. Once the work in the branch is completed, you can merge all changes down to the trunk.
    Thanks. Makes sense. Out of interest, will SVN/CVS tell you if it can't merge a branch and a trunk properly, or will it not be able to tell if it has merged properly (since it doesn't test the code)?

  7. #7
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Sounds like you might want a distributed source control system. Check out git. Each developer has their own branch or even multiple. It is supposedly much easier to merge then the CVS derivatives. Also, because it is distributed there is not a centralized copy of your work. It will go out to everyone else who is working on the project as well. So if you ever crash you can get your work from someone else.

    Meh, its hard to explain. Check out Linus Torvald's talk on it for a better explication. http://www.youtube.com/watch?v=4XpnKHJAok8

    Seems interesting to me at least
    Last edited by The New Guy; Jul 17, 2007 at 08:56.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Seantyr View Post
    Is it possible to configure SVN or CVS to 'build a nightly' in a web-accessable directory that doesn't change, i.e. the previous night's code gets overwritten with the new night's code? I don't want to try to have to explain to these other people working on the game that they have to update their bookmarks every night to reflect new directories.
    You'd probably just set up a PHP script to run by a cronjob. Alternatively, SVN can be configured to trigger a script after each checkin.

    Quote Originally Posted by Seantyr View Post
    I guess my idea of making a tag as soon as I made a change to the code would be quite inefficient too, since the version controller would need to read every diff involved in the program and create a copy.
    SVN is quite efficient at making branches. It doesn't actually copy the files, until it needs to.

    I understand. That makes it sound very simple, actually. I guess my idea of making a tag as soon as I made a change to the code would be quite inefficient too, since the version controller would need to read every diff involved in the program and create a copy.

    Quote Originally Posted by Seantyr View Post
    Out of interest, will SVN/CVS tell you if it can't merge a branch and a trunk properly, or will it not be able to tell if it has merged properly (since it doesn't test the code)?
    If it can't auto-merge changes, you will get a conflict. You then have to resolve the conflict manually. In the basic incarnation, you can use any text editor for this, but specialised diff-tools exists. Most IDE's an programmers editors have some built-in tool. The TortoiseSVN client (A windows SVN client) has a tool as well.

    Welcome to Sitepoint btw.

  9. #9
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So finally we come to the ultimate question:

    All I really need from version control is a way of being able to track edits, roll back to previous diffs after I make mistakes, and allow branches. I would merge branches once in a blue moon, but I would like the option to be available. I am probably going to be the only developer working on the code of the project. I like the idea behind Git's per-line tracking as opposed to per-file tracking (where, for instance, if you moved a function from one file to another, you could view the history of that function rather than of the two files involved in the move), but it isn't mandatory. There will also have to be a Windows XP tool available for doing whatever needs done edit-wise, though my server uses CentOS so the actual version controller will need to be Linux-based (like that's an issue!).

    Which version system do you think will suit me best?

  10. #10
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Between SVN and CVS, SVN is superior in all aspects. So I wouldn't recommend CVS.
    SVN and CVS are by far more widespread than GIT. I've heard a lot of good things about GIT, but never used it. If you don't need the features, I think you're better off going with the mainstream and use SVN. You're more likely to get support and general support by tools etc.

  11. #11
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's what I thought. I've read bits and pieces claiming CVS does some things better than SVN, but apparently not.

    Any idiot-proof guides to setting up SVN on a server?

  12. #12
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SVN is based on CVS so it should contain any features CVS has.
    For detailled info on installing, using etc. search for the "svn book" on google.
    I just set SVN up with Apache - it's a bit hairy if you've never done before but when it works you got many, many options like full SSL and auth support from Apache.

  13. #13
    SitePoint Zealot Mau's Avatar
    Join Date
    Jan 2006
    Location
    California, USA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to check out SVK, which is distributed and sits on top of SVN. You get the best of both worlds here.

  14. #14
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SVN is really very simple to set up with Apache; you just have to make sure you get the permissions right because you don't want your repository writeable by anyone who shouldn't be writing to it.

    I just set subversion up over the weekend in fact, so if you happen to have any problems with it feel free to ask me. But I'd recommend reading chapter 6 of the Subversion book, which pretty much provides all the information you might ever need.

    Sorry to drop in late, but I figured the above might be of some use.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •