tutorial: second chapter about changing a file
authorHervé Cauwelier <herve@oursours.net>
Thu, 17 Sep 2009 20:27:05 +0000 (22:27 +0200)
committerHervé Cauwelier <herve@oursours.net>
Thu, 17 Sep 2009 20:27:05 +0000 (22:27 +0200)
docs/tutorial/1-initial-commit.txt
docs/tutorial/2-change_file.txt [new file with mode: 0644]
docs/tutorial/Makefile
docs/tutorial/index.txt

index 0349f15de656b6a5d23620bcc19ffbc7d0329663..62d02a2b32a70ea162ebb17407bd1de47a8e8906 100644 (file)
@@ -58,7 +58,8 @@ job of the commit::
   >>> from time import time
   >>> commit = Commit()
   >>> commit.tree = tree.id
-  >>> commit.author = commit.committer = "Your Name <your.email@example.com>"
+  >>> author = "Your Name <your.email@example.com>"
+  >>> commit.author = commit.committer = author
   >>> commit.commit_time = commit.author_time = int(time())
   >>> tz = parse_timezone('-0200')
   >>> commit.commit_timezone = commit.author_timezone = tz
diff --git a/docs/tutorial/2-change_file.txt b/docs/tutorial/2-change_file.txt
new file mode 100644 (file)
index 0000000..4f75c2f
--- /dev/null
@@ -0,0 +1,61 @@
+Changing a File and Commit it
+=============================
+
+Now we have a first commit, the next one will show a difference.
+
+As seen in the introduction, it's about making a path in a tree point to a
+new blob. The old blob will remain to compute the diff. The tree is altered
+and the new commit'task is to point to this new version.
+
+In the following examples, we assume we still have the ``repo`` and ``tree``
+object from the previous chapter.
+
+Let's first build the blob::
+
+  >>> spam = Blob.from_string("My new file content")
+  >>> spam.id
+  'fd2a0fa3ad828c5bda4b7badcbe522dc3b12af73'
+
+An alternative is to alter the previously constructed blob object::
+
+  >>> blob.data = "My new file content"
+  >>> blob.id
+  'fd2a0fa3ad828c5bda4b7badcbe522dc3b12af73'
+
+In any case, update the blob id known as "spam". You also have the
+opportunity of changing its mode::
+
+  >>> tree["spam"] = (0100644, spam.id)
+
+Now let's record the change::
+
+  >>> c2 = Commit()
+  >>> c2.tree = tree.id
+  >>> c2.parents = [commit.id]
+  >>> c2.author = c2.committer = author
+  >>> c2.commit_time = c2.author_time = int(time())
+  >>> c2.commit_timezone = c2.author_timezone = tz
+  >>> c2.encoding = "UTF-8"
+  >>> c2.message = 'Changing "spam"'
+
+In this new commit we record the changed tree id, and most important, the
+previous commit as the parent. Parents are actually a list because a commit
+may happen to have several parents after merging branches.
+
+Remain to record this whole new family::
+
+  >>> object_store.add_object(spam)
+  >>> object_store.add_object(tree)
+  >>> object_store.add_object(c2)
+
+You can already ask git to introspect this commit using ``git show`` and the
+value of ``commit.it`` as an argument. You'll see the difference will the
+previous blob recorded as "spam".
+
+You won't see it using git log because the head is still the previous
+commit. It's easy to remedy::
+
+  >>> repo.refs['refs/heads/master'] = commit.id
+
+Now all git tools will work as expected. Though don't forget that Dulwich is
+still open!
index e824454a438c903e08bee6441e77f8f44dbb039f..08daf8b25f354286be9775f050efa94bc735f88c 100644 (file)
@@ -1,4 +1,11 @@
+TXT=$(shell ls *.txt)
+
 ALL: index.html
 
-index.html: index.txt
-       rst2html.py $< $@
+index.html: $(TXT)
+       rst2html.py index.txt index.html
+
+clean:
+       rm -f index.html
+
+.PHONY: clean
index afc556a4c16148877412f71a1ace454982e1a79e..b6baa9a23e64228356c71bef8f07f5a85cbda1b1 100644 (file)
@@ -6,3 +6,4 @@ Dulwich Tutorial
 
 .. include:: 0-introduction.txt
 .. include:: 1-initial-commit.txt
+.. include:: 2-change_file.txt