introduction.txt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. .. _tutorial-introduction:
  2. Introduction
  3. ============
  4. Git repository format
  5. ---------------------
  6. For a better understanding of Dulwich, we'll start by explaining most of the
  7. Git secrets.
  8. Open the ".git" folder of any Git-managed repository. You'll find folders
  9. like "branches", "hooks"... We're only interested in "objects" here. Open it.
  10. You'll mostly see 2 hex-digits folders. Git identifies content by its SHA-1
  11. digest. The 2 hex-digits plus the 38 hex-digits of files inside these folders
  12. form the 40 characters (or 20 bytes) id of Git objects you'll manage in
  13. Dulwich.
  14. We'll first study the three main objects:
  15. - The Commit;
  16. - The Tree;
  17. - The Blob.
  18. The Commit
  19. ----------
  20. You're used to generate commits using Git. You have set up your name and
  21. e-mail, and you know how to see the history using ``git log``.
  22. A commit file looks like this::
  23. commit <content length><NUL>tree <tree sha>
  24. parent <parent sha>
  25. [parent <parent sha> if several parents from merges]
  26. author <author name> <author e-mail> <timestamp> <timezone>
  27. committer <author name> <author e-mail> <timestamp> <timezone>
  28. <commit message>
  29. But where are the changes you commited? The commit contains a reference to a
  30. tree.
  31. The Tree
  32. --------
  33. A tree is a collection of file information, the state of a single directory at
  34. a given point in time.
  35. A tree file looks like this::
  36. tree <content length><NUL><file mode> <filename><NUL><item sha>...
  37. And repeats for every file in the tree.
  38. Note that the SHA-1 digest is in binary form here.
  39. The file mode is like the octal argument you could give to the ``chmod``
  40. command. Except it is in extended form to tell regular files from
  41. directories and other types.
  42. We now know how our files are referenced but we haven't found their actual
  43. content yet. That's where the reference to a blob comes in.
  44. The Blob
  45. --------
  46. A blob is simply the content of files you are versionning.
  47. A blob file looks like this::
  48. blob <content length><NUL><content>
  49. If you change a single line, another blob will be generated by Git at commit
  50. time. This is how Git can fastly checkout any version in time.
  51. On the opposite, several identical files with different filenames generate
  52. only one blob. That's mostly how renames are so cheap and efficient in Git.
  53. Dulwich Objects
  54. ---------------
  55. Dulwich implements these three objects with an API to easily access the
  56. information you need, while abstracting some more secrets Git is using to
  57. accelerate operations and reduce space.
  58. More About Git formats
  59. ----------------------
  60. These three objects make up most of the contents of a Git repository and are
  61. used for the history. They can either appear as simple files on disk (one file
  62. per object) or in a ``pack`` file, which is a container for a number of these
  63. objects.
  64. The is also an index of the current state of the working copy in the
  65. repository as well as files to track the existing branches and tags.
  66. For a more detailed explanation of object formats and SHA-1 digests, see:
  67. http://www-cs-students.stanford.edu/~blynn/gitmagic/ch08.html
  68. Just note that recent versions of Git compress object files using zlib.