5

I am new to SVN and I want to commit a code to SVN using TortoiseSVN. I have C++ headers and source of the code, but I don't know how to organize the folders in an efficient way before uploading the version to SVN. Any suggestions about how people usually do? Is there any difference between the structure of codes for different languages, for example C++ or java. Should I follow any specific rules?

Update

So after checking the answers I made things a bit clearer. An usual folder structure is the following for one proyect:

/trunk
/branches
/tags

But I also found a similar structure that I liked a lot, which is:

/trunk                  #Keep it to developement mode always.
    /samples            #samples of use
    /modules            #software modules
       /project_modName
           /include     # .hpp files
           /src         # .cpp files
    /test               #unitary tests
/branches               #experimental developements (copies of trunk at various stages)
/tags                   #estable versions
/extras
    /3rdparty           #libs
    /data               #necessary data for developement
    /doc                #documentation
    /resources          #for window applications

At least I like it for multimedia applications code.

UPDATE 2

This update is just to explain how I am creating my repository. I created a folder called structure_svn. Inside I created the structure showned above. I right click on the parent folder and select import. In URL I write the folder path (file:///c:/svn_repos) so automatically the structure is created under svn_repos, without the folder structure_svn.

I want to remark this beacause the folder you right-click on to import will never appear. I just realized when I tried it, and also is explained on toturials.

The next step is to successfuly divide my code inside the created structure.

Community
  • 1
  • 1
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
  • From my experiences the most common things to look out for is including automatically generated files and IDE user files. Those things you don't really notice until working on a shared project. – r_ahlskog Dec 21 '11 at 12:04
  • 1
    Do you mean error logs, for example? Actually I was mostly thinking about folders structure and son on, how to name them and how to organize them. – Jav_Rock Dec 21 '11 at 12:18
  • 1
    I mean for example *.designer.cs files that are generated from .resx files. Also I know you wanted a project layout/naming, but I am still struggling with that myself after 5 years so best I can suggest is look around, most open source projects lets you look at their source control, find something you like and go from there. – r_ahlskog Dec 21 '11 at 12:22
  • @Jav_Rock The structure you found also seems very good. I might adapt a few things. – Paul Manta Dec 21 '11 at 16:15

4 Answers4

9

Here's how I structure my tree in a programming project (mainly from a C/C++ perspective):

  • /
    • src — Source and header files written by myself
    • ext — External dependencies; contains third-party libraries
      • libname-1.2.8
        • include — Headers
        • lib — Compiled lib files
        • Donwload.txt — Contains link to download the version used
    • ide — I store project files in here
      • vc10 — I arrange project files by IDE
    • bin — Compiled binaries go here
    • obj — The compiler's build files
      • gcc — If your project size justifies it, make a separate folder for each compiler's files
    • doc — Documentation of any kind
    • README
    • INSTALL
    • COPYING
    • makefile — Something to automate generation of IDE project files. I prefer CMake.

A few notes:

  1. If I'm writing a library (and I'm using C/C++) I'm going to organize my source files first in two folders called "src/include" and "src/source" and then by module. If it's an application, then I'm going to organize them just by module (headers and sources will go in the same folder).

  2. Files and directories that I listed above in italics I won't add to the code repository.

Edit: Note that I'm using Mercurial, not SVN, so the structure above it tailored for that version control system. Anyway, I see from your update that you already found one that you like.

Paul Manta
  • 30,618
  • 31
  • 128
  • 208
  • src without ide doesn't seem particularly useful. How do you build huge projects without any project file (be it a Makefile/CMakeFile/cvproj).. – stijn Dec 21 '11 at 12:26
  • @stijn Of course you should have some kind of makefile present (I prefer CMake, personally). I'll add that to the list, to avoid confusion. :) – Paul Manta Dec 21 '11 at 12:28
4

One huge step forward is making sure all your projects do out-of-source builds, ie put temporary file in $TEMP and put all output file in a dedicated bin/lib directory. If done properly, this leaves you with source directories containing only source. What's in a name.. Apart from 'pure' source files also make sure that everything needed to build the source is in the repository: project files/generators, resources.

Once you got that in place correctly, there's a good chance you only have to put some typical project generated files (like *.suo for Visual Studio) into SVN's ignore list, and you're ready for commit.

stijn
  • 34,664
  • 13
  • 111
  • 163
4

Basically you can put in svn just what you want. The only standard you might consider to follow here is the standard repository layout: See here:

Within the project you are right that there exists several best practices. And they are different for each language. E.g a Java Package is organized by namespace. In the C++ world I have seen two main ways how to organize it:

  • Every Class into a header (.h) and a source file (.cpp) inside the same directory
  • Header and source is separated (so you have an folder especially for headers) This is usefull for libraries so that this path can be used by upper layer projects.

Then you need a folder for third party libs, another one for the target files and others such as build files or documentation.

Community
  • 1
  • 1
schoetbi
  • 12,009
  • 10
  • 54
  • 72
4

You have a good explanation in the next Link if you are noob with svn!!

vgonisanz
  • 11,831
  • 13
  • 78
  • 130