Skip to content

Commit

Permalink
Updated readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Nov 7, 2023
1 parent 19b557c commit 120d326
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 10 deletions.
74 changes: 69 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ It primarily fits the purpose of easily extracting commit information from a Git

### Target .NET platforms

* .NET 7.0 to 5.0
* .NET 8.0 to 5.0
* .NET Core 3.1 to 2.0
* .NET Standard 2.1 to 1.6
* .NET Framework 4.8.1 to 3.5
Expand All @@ -78,7 +78,7 @@ It primarily fits the purpose of easily extracting commit information from a Git
F# 5.0 or upper, it contains F# friendly signature definition.
(Asynchronous operations with `Async` type, elimination of null values with `Option`, etc.)

* .NET 7.0 to 5.0
* .NET 8.0 to 5.0
* .NET Core 3.1 to 2.0
* .NET Standard 2.1, 2.0
* .NET Framework 4.8.1 to 4.6.1
Expand Down Expand Up @@ -261,7 +261,7 @@ foreach (Stash stash in repository.Stashes)

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
Commit[] parents = await commit.GetParentCommitsAsync();

Expand All @@ -283,7 +283,7 @@ The code shown here does not actually 'check out', but reads these structures as

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

Expand All @@ -300,7 +300,7 @@ if (await repository.GetCommitAsync(

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

Expand All @@ -317,6 +317,37 @@ if (await repository.GetCommitAsync(
}
```

### Reading a submodule in commit tree.

You can also identify references to submodules.
However, if you want to reference information in a submodule, you must open a new repository.
This is accomplished with `OpenSubModuleAsync()`.

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

foreach (TreeEntry entry in treeRoot.Children)
{
// For a submodule, the instance type is `TreeSubModuleEntry`.
if (entry is TreeSubModuleEntry subModule)
{
// Open this submodule repository.
using var subModuleRepository = await subModule.OpenSubModuleAsync();

// Retreive the commit hash specified in the original repository.
if (await subModuleRepository.GetCommitAsync(
subModule.Hash) is Commit subModuleCommit)
{
// ...
}
}
}
}
```

### Traverse a branch through primary commits

A commit in Git can have multiple parent commits.
Expand Down Expand Up @@ -497,6 +528,36 @@ if (await repository.GetCommitAsync(
}
```

### Reading a submodule in commit tree.

```csharp
if (await repository.GetCommitAsync(
"1205dc34ce48bda28fc543daaf9525a9bb6e6d10") is PrimitiveCommit commit)
{
PrimitiveTree tree = await repository.GetTreeAsync(commit.TreeRoot);

foreach (Hash childHash in tree.Children)
{
PrimitiveTreeEntry child = await repository.GetTreeAsync(childHash);

// If this tree entry is a submodule.
if (child.SpecialModes == PrimitiveSpecialModes.SubModule)
{
// The argument must be a "tree path".
// It is the sequence of all paths from the repository root up to this entry.
using var subModuleRepository = await repository.OpenSubModuleAsync(
new[] { child });

if (await repository.GetCommitAsync(
child.Hash) is PrimitiveCommit subModuleCommit)
{
// ...
}
}
}
}
```

### Traverse a commit through primary commits

```csharp
Expand Down Expand Up @@ -574,6 +635,9 @@ Apache-v2

## History

* 1.6.0:
* Added submodule accessor.
* Fixed invalid remote url entries at multiple declaration. (#10)
* 1.5.0:
* Included .NET 8.0 RC2 assembly (`net8.0`).
* 1.4.0:
Expand Down
71 changes: 66 additions & 5 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (repository.Head is { } head)

### 対応する.NETプラットフォーム

* .NET 7.0 to 5.0
* .NET 8.0 to 5.0
* .NET Core 3.1 to 2.0
* .NET Standard 2.1 to 1.6
* .NET Framework 4.8.1 to 3.5
Expand All @@ -79,7 +79,7 @@ if (repository.Head is { } head)
F# 5.0以上が対象で、F#フレンドリーなシグネチャ定義が含まれています。
(`Async`型による非同期操作、`Option`によるnull値排除など)

* .NET 7.0 to 5.0
* .NET 8.0 to 5.0
* .NET Core 3.1 to 2.0
* .NET Standard 2.1, 2.0
* .NET Framework 4.8.1 to 4.6.1
Expand Down Expand Up @@ -259,7 +259,7 @@ foreach (Stash stash in repository.Stashes)

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
Commit[] parents = await commit.GetParentCommitsAsync();

Expand All @@ -281,7 +281,7 @@ if (await repository.GetCommitAsync(

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

Expand All @@ -298,7 +298,7 @@ if (await repository.GetCommitAsync(

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Command commit)
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

Expand All @@ -315,6 +315,37 @@ if (await repository.GetCommitAsync(
}
```

### コミット内のサブモジュールの読み取り

サブモジュールへの参照を識別することも出来ます。
但し、サブモジュール内の情報を参照する場合は、新たにリポジトリをオープンすることになります。
これを実現するのが、 `OpenSubModuleAsync()` です。

```csharp
if (await repository.GetCommitAsync(
"6961a50ef3ad4e43ed9774daffd8457d32cf5e75") is Commit commit)
{
TreeRoot treeRoot = await commit.GetTreeRootAsync();

foreach (TreeEntry entry in treeRoot.Children)
{
// サブモジュールの場合はインスタンスの型が`TreeSubModuleEntry`です
if (entry is TreeSubModuleEntry subModule)
{
// サブモジュールリポジトリをオープンします
using var subModuleRepository = await subModule.OpenSubModuleAsync();

// 元のリポジトリで指定されているコミットを参照して取得します
if (await subModuleRepository.GetCommitAsync(
subModule.Hash) is Commit subModuleCommit)
{
// ...
}
}
}
}
```

### コミットのプライマリ親コミットを再帰的に取得

Gitのコミットは、複数の親コミットを持つ事があります。
Expand Down Expand Up @@ -492,6 +523,36 @@ if (await repository.GetCommitAsync(
}
```

### コミット内のサブモジュールの読み取り

```csharp
if (await repository.GetCommitAsync(
"1205dc34ce48bda28fc543daaf9525a9bb6e6d10") is PrimitiveCommit commit)
{
PrimitiveTree tree = await repository.GetTreeAsync(commit.TreeRoot);

foreach (Hash childHash in tree.Children)
{
PrimitiveTreeEntry child = await repository.GetTreeAsync(childHash);

// このツリーエントリがサブモジュールの場合
if (child.SpecialModes == PrimitiveSpecialModes.SubModule)
{
// 引数には「ツリーパス」が必要です。
// これは、このエントリに至るまでの、リポジトリルートからの全てのパス列です。
using var subModuleRepository = await repository.OpenSubModuleAsync(
new[] { child });

if (await repository.GetCommitAsync(
child.Hash) is PrimitiveCommit subModuleCommit)
{
// ...
}
}
}
}
```

### コミットのプライマリ親コミットを再帰的に取得

```csharp
Expand Down

0 comments on commit 120d326

Please sign in to comment.