forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitCheckoutOptsWrapper.cs
More file actions
86 lines (73 loc) · 2.95 KB
/
GitCheckoutOptsWrapper.cs
File metadata and controls
86 lines (73 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
namespace LibGit2Sharp.Core
{
/// <summary>
/// A wrapper around the native GitCheckoutOpts structure. This class is responsible
/// for the managed objects that the native code points to.
/// </summary>
internal class GitCheckoutOptsWrapper : IDisposable
{
/// <summary>
/// Create wrapper around <see cref="GitCheckoutOpts"/> from <see cref="CheckoutOptions"/>.
/// </summary>
/// <param name="options">Options to create native GitCheckoutOpts structure from.</param>
/// <param name="paths">Paths to checkout.</param>
public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[] paths = null)
{
Callbacks = options.GenerateCallbacks();
if (paths != null)
{
PathArray = GitStrArrayManaged.BuildFrom(paths);
}
Options = new GitCheckoutOpts
{
version = 1,
checkout_strategy = options.CheckoutStrategy,
progress_cb = Callbacks.CheckoutProgressCallback,
notify_cb = Callbacks.CheckoutNotifyCallback,
notify_flags = options.CheckoutNotifyFlags,
paths = PathArray.Array,
};
}
/// <summary>
/// Native struct to pass to libgit.
/// </summary>
public GitCheckoutOpts Options { get; set; }
/// <summary>
/// The managed class mapping native callbacks into the
/// corresponding managed delegate.
/// </summary>
public CheckoutCallbacks Callbacks { get; private set; }
/// <summary>
/// Keep the paths around so we can dispose them.
/// </summary>
private GitStrArrayManaged PathArray;
public void Dispose()
{
PathArray.Dispose();
}
/// <summary>
/// Method to translate from <see cref="CheckoutFileConflictStrategy"/> to <see cref="CheckoutStrategy"/> flags.
/// </summary>
internal static CheckoutStrategy CheckoutStrategyFromFileConflictStrategy(CheckoutFileConflictStrategy fileConflictStrategy)
{
CheckoutStrategy flags = default(CheckoutStrategy);
switch (fileConflictStrategy)
{
case CheckoutFileConflictStrategy.Ours:
flags = CheckoutStrategy.GIT_CHECKOUT_USE_OURS;
break;
case CheckoutFileConflictStrategy.Theirs:
flags = CheckoutStrategy.GIT_CHECKOUT_USE_THEIRS;
break;
case CheckoutFileConflictStrategy.Merge:
flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_MERGE;
break;
case CheckoutFileConflictStrategy.Diff3:
flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
break;
}
return flags;
}
}
}