From d9dacf56d8e1ec16f718119765af128d16232954 Mon Sep 17 00:00:00 2001 From: IceNature Date: Tue, 18 Aug 2015 12:26:50 +0800 Subject: [PATCH 1/3] Sync B-embedding-git jgit --- book/B-embedding-git/sections/jgit.asc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/book/B-embedding-git/sections/jgit.asc b/book/B-embedding-git/sections/jgit.asc index e35136af..37bcfc84 100644 --- a/book/B-embedding-git/sections/jgit.asc +++ b/book/B-embedding-git/sections/jgit.asc @@ -8,7 +8,7 @@ JGit 项目由 Eclipse 维护,它的主页在 http://www.eclipse.org/jgit[] ==== 起步 有很多种方式可以让 JGit 连接你的项目,并依靠它去写代码。 -最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 `dependencies` 标签中增加像下面这样的片段来完成这个整合。 +最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 ``` 标签中增加像下面这样的片段来完成这个整合。 [source,xml] ---- @@ -25,7 +25,7 @@ JGit 项目由 Eclipse 维护,它的主页在 http://www.eclipse.org/jgit[] 如果你想自己管理二进制的依赖包,那么你可以从 http://www.eclipse.org/jgit/download[] 获得预构建的 JGit 二进制文件。 你可以像下面这样执行一个命令来将它们构建进你的项目。 -[source,shell] +[source,console] ---- javac -cp .:org.eclipse.jgit-3.5.0.201409260305-r.jar App.java java -cp .:org.eclipse.jgit-3.5.0.201409260305-r.jar App @@ -41,9 +41,10 @@ JGit 的 API 有两种基本的层次:底层命令和高层命令。 [source,java] ---- -// 创建一个新仓库,路径必须存在 +// 创建一个新仓库 Repository newlyCreatedRepo = FileRepositoryBuilder.create( new File("/tmp/new_repo/.git")); +newlyCreatedRepo.create(); // 打开一个存在的仓库 Repository existingRepo = new FileRepositoryBuilder() @@ -69,21 +70,21 @@ ObjectId masterTip = master.getObjectId(); ObjectId obj = repo.resolve("HEAD^{tree}"); // 装载对象原始内容 -ObjectLoader loader = r.open(masterTip); +ObjectLoader loader = repo.open(masterTip); loader.copyTo(System.out); // 创建分支 -RefUpdate createBranch1 = r.updateRef("refs/heads/branch1"); +RefUpdate createBranch1 = repo.updateRef("refs/heads/branch1"); createBranch1.setNewObjectId(masterTip); createBranch1.update(); // 删除分支 -RefUpdate deleteBranch1 = r.updateRef("refs/heads/branch1"); +RefUpdate deleteBranch1 = repo.updateRef("refs/heads/branch1"); deleteBranch1.setForceUpdate(true); deleteBranch1.delete(); // 配置 -Config cfg = r.getConfig(); +Config cfg = repo.getConfig(); String name = cfg.getString("user", null, "name"); ---- From 6ccc748aff5a5f43bde5bbc81520020b84620653 Mon Sep 17 00:00:00 2001 From: IceNature Date: Tue, 18 Aug 2015 12:28:07 +0800 Subject: [PATCH 2/3] Sync B-embedding-git libgit2 --- book/B-embedding-git/sections/libgit2.asc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book/B-embedding-git/sections/libgit2.asc b/book/B-embedding-git/sections/libgit2.asc index 84efb145..b9a2c331 100644 --- a/book/B-embedding-git/sections/libgit2.asc +++ b/book/B-embedding-git/sections/libgit2.asc @@ -228,8 +228,9 @@ Python 的 Libgit2 绑定叫做 Pygit2 ,你可以在 http://www.pygit2.org/[] [source,python] ---- pygit2.Repository("/path/to/repo") # 打开版本库 - .head.resolve() # 获取直接引用 - .get_object().message # 获取提交,读取信息。 + .head # get the current branch + .peel(pygit2.Commit) # walk down to the commit + .message # read the message ---- From 47aa5902a56ac7f86a177e8bdabfe02704d0dc43 Mon Sep 17 00:00:00 2001 From: IceNature Date: Tue, 18 Aug 2015 12:35:36 +0800 Subject: [PATCH 3/3] Delete a extra ` --- book/B-embedding-git/sections/jgit.asc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/B-embedding-git/sections/jgit.asc b/book/B-embedding-git/sections/jgit.asc index 37bcfc84..abb212a3 100644 --- a/book/B-embedding-git/sections/jgit.asc +++ b/book/B-embedding-git/sections/jgit.asc @@ -8,7 +8,7 @@ JGit 项目由 Eclipse 维护,它的主页在 http://www.eclipse.org/jgit[] ==== 起步 有很多种方式可以让 JGit 连接你的项目,并依靠它去写代码。 -最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 ``` 标签中增加像下面这样的片段来完成这个整合。 +最简单的方式也许就是使用 Maven 。你可以通过在你的 pom.xml 文件里的 `` 标签中增加像下面这样的片段来完成这个整合。 [source,xml] ----