I know what recursion is in programming. I do understand the basics of version control systems (have used svn that is). But I have often wondered what the meaning of "recursion" or "recursive" is with respect to version control systems.

What does a function calling itself have to do with working with files and directories in a version control system?

  • 1
    Can you give an example of where you've seen this term used? Jan 23, 2013 at 17:57
  • 2
    You may want to edit this question and title to not specifically refer to version control systems -- this usage is general to programs operating on a directory and its contents (see answer below).
    – jimwise
    Jan 23, 2013 at 18:01

1 Answer 1


The specific meaning of "recursive" in this context is "operating on a directory and its contents, including the contents of any subdirectories".

The word "recursive" is used here, because at least conceptually, this is easily implemented by a recursive algorithm:

procedure check_in_directory (d : directory)
    for each entry e in d             <== recursive exit after last entry in directory
        if e is a file
        if e is a directory
            check_in_directory(e)     <== recursive call

The recursive structure of this procedure matches the recursive definition of a directory:

  • A directory contains zero or more directory entries

  • A directory entry is either a file or a directory

This approach -- writing a function whose structure matches the definition of the data type you are processing is often referred to as structural recursion.

  • 4
    +1 a file system is a tree structure. Recursion and tree structures go hand in hand (some might say they are the same thing).
    – MattDavey
    Jan 23, 2013 at 18:45
  • If you look at the "directory" as an abstract thing, you could say the the function "look in the directory" calls itself, as long as no other directories are in it. Exactly as @jimwise showed you in his code.
    – mhr
    Jan 23, 2013 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.