Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
Can you give an example of where you've seen this term used? –  jozefg Jan 23 '13 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 '13 at 18:01
add comment

1 Answer

up vote 24 down vote accepted

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
            check_in_file(f)
        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.

share|improve this answer
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 '13 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. –  mri Jan 23 '13 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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