我的站点

一个系统软件工程师的随手涂鸦

Date: 八月 28, 2015

Git数据模型笔记

Git object数据是一个有向无环图,即从任何一个commit出发都可以遍历其任何的parent,但绝不会有环。每个commit都指向一个tree,而一个tree则指向了一个或多个tree和(或)blob

Git数据模型如下图所示:

1

以下面目录结构为例:

2

工作目录下包含了两个目录和三个文件。初始化的git数据模型如下:

3

当修改lib/base/base_include.rb这个文件并提交以后,会产生一个新的blob以及相应的新tree。在当前commit打出tag以后,git数据模型如下:

4

修改根目录下init.rb文件提交后的git数据模型:

5

可以看到,每次commit都会产生一个新的tree
最后的git数据模型如下图所示,包含了16个不可改变的object

6

 

 

参考资料:
Git internals

git小技巧(7)——“git format-patch ..

git format-patch <rev1>..<rev2>会产生两个commit之间的patch<rev>commit ID)。请看例子:

[root@localhost linux]# git format-patch 9f10e5bf62f7b9937afeee8ff0a491f87438e2a2..571dbbd4d044e11c78bc077acb3ccef4c77b096e
0001-iommu-vt-d-Init-QI-before-root-entry-is-allocated.patch
0002-iommu-vt-d-Make-root-entry-visible-for-hardware-righ.patch
0003-iommu-vt-d-Detect-pre-enabled-translation.patch
0004-iommu-vt-d-Copy-translation-tables-from-old-kernel.patch
0005-iommu-vt-d-Do-not-re-use-domain-ids-from-the-old-ker.patch
0006-iommu-vt-d-Mark-copied-context-entries.patch
0007-iommu-vt-d-Allocate-si_domain-in-init_dmars.patch
0008-iommu-vt-d-Don-t-do-early-domain-assignment-if-kdump.patch
0009-iommu-vt-d-Don-t-copy-translation-tables-if-RTT-bit-.patch
0010-iommu-vt-d-Don-t-disable-translation-prior-to-OS-han.patch
0011-iommu-vt-d-Enable-Translation-only-if-it-was-previou.patch
0012-iommu-vt-d-Move-EIM-detection-to-intel_prepare_irq_r.patch
0013-iommu-vt-d-Move-QI-initializationt-to-intel_setup_ir.patch
0014-iommu-vt-d-Disable-IRQ-remapping-in-intel_prepare_ir.patch
0015-iommu-vt-d-Set-IRTA-in-intel_setup_irq_remapping.patch
0016-iommu-vt-d-Copy-IR-table-from-old-kernel-when-in-kdu.patch
0017-iommu-vt-d-Make-sure-copied-over-IR-entries-are-not-.patch
0018-iommu-vt-d-Don-t-disable-IR-when-it-was-previously-e.patch

但是这个命令不会包含<rev1>这个commit产生的patch。要想包含<rev1>这个commit产生的patch,需要在<rev1>后加上~,代表<rev1>之前的commit。请看例子:

[root@localhost linux]# git format-patch 9f10e5bf62f7b9937afeee8ff0a491f87438e2a2~..571dbbd4d044e11c78bc077acb3ccef4c77b096e
0001-iommu-vt-d-Cleanup-log-messages.patch
0002-iommu-vt-d-Init-QI-before-root-entry-is-allocated.patch
0003-iommu-vt-d-Make-root-entry-visible-for-hardware-righ.patch
0004-iommu-vt-d-Detect-pre-enabled-translation.patch
0005-iommu-vt-d-Copy-translation-tables-from-old-kernel.patch
0006-iommu-vt-d-Do-not-re-use-domain-ids-from-the-old-ker.patch
0007-iommu-vt-d-Mark-copied-context-entries.patch
0008-iommu-vt-d-Allocate-si_domain-in-init_dmars.patch
0009-iommu-vt-d-Don-t-do-early-domain-assignment-if-kdump.patch
0010-iommu-vt-d-Don-t-copy-translation-tables-if-RTT-bit-.patch
0011-iommu-vt-d-Don-t-disable-translation-prior-to-OS-han.patch
0012-iommu-vt-d-Enable-Translation-only-if-it-was-previou.patch
0013-iommu-vt-d-Move-EIM-detection-to-intel_prepare_irq_r.patch
0014-iommu-vt-d-Move-QI-initializationt-to-intel_setup_ir.patch
0015-iommu-vt-d-Disable-IRQ-remapping-in-intel_prepare_ir.patch
0016-iommu-vt-d-Set-IRTA-in-intel_setup_irq_remapping.patch
0017-iommu-vt-d-Copy-IR-table-from-old-kernel-when-in-kdu.patch
0018-iommu-vt-d-Make-sure-copied-over-IR-entries-are-not-.patch
0019-iommu-vt-d-Don-t-disable-IR-when-it-was-previously-e.patch

可以看到多产生了一个patch

Lua笔记(22)—— error和assert

Lua中的error函数定义:

error (message [, level])

打印出message后,会终止程序运行。关于level的含义,参考下面例子理解会更清楚(test.lua):

function f0()
        error("Error!")
end

function f1()
        f0()
end

function f2()
        f1()
end

f2()

执行如下:

lua: test.lua:2: Error!
stack traceback:
        [C]: in function 'error'
        test.lua:2: in function 'f0'
        test.lua:6: in function 'f1'
        test.lua:10: in function 'f2'
        test.lua:13: in main chunk
        [C]: in ?

默认情况下,level值为1。“lua: test.lua:2: Error!”把错误位置指向了脚本的第2行。把f0函数修改一下:

function f0()
        error("Error!")
end

再次执行,输出如下:

lua: test.lua:6: Error!
stack traceback:
        [C]: in function 'error'
        test.lua:2: in function 'f0'
        test.lua:6: in function 'f1'
        test.lua:10: in function 'f2'
        test.lua:13: in main chunk
        [C]: in ?

这次错误位置指向了脚本的第6行(“lua: test.lua:6: Error!”),也就是f1()函数,可以看到level指定了发生错误时,应该输出函数调用栈的哪一级函数。

assert函数定义如下:

assert (v [, message])

v是假(nilfalse)时,调用error函数,否则返回所有所有参数。其中message默认值是"assertion failed!"。举例如下:

function f0()
        assert(nil, "Assert!")
end
f0()

输出如下:

lua: test.lua:2: Assert!
stack traceback:
        [C]: in function 'assert'
        test.lua:2: in function 'f0'
        test.lua:13: in main chunk
        [C]: in ?

Powered by WordPress & Theme by Anders Norén