7

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?

jimwise
  • 7,578
  • 1
  • 30
  • 32
minusSeven
  • 723
  • 1
  • 7
  • 17
  • 1
    Can you give an example of where you've seen this term used? – daniel gratzer 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

1 Answers1

31

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.

jimwise
  • 7,578
  • 1
  • 30
  • 32
  • 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. – mhr Jan 23 '13 at 19:14