-
Notifications
You must be signed in to change notification settings - Fork 894
/
Copy pathTreeEntryChanges.cs
119 lines (104 loc) · 4.1 KB
/
TreeEntryChanges.cs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Holds the changes between two versions of a tree entry.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class TreeEntryChanges
{
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected TreeEntryChanges()
{ }
internal unsafe TreeEntryChanges(git_diff_delta* delta)
{
Path = LaxUtf8Marshaler.FromNative(delta->new_file.Path);
OldPath = LaxUtf8Marshaler.FromNative(delta->old_file.Path);
Mode = (Mode)delta->new_file.Mode;
OldMode = (Mode)delta->old_file.Mode;
Oid = ObjectId.BuildFromPtr(&delta->new_file.Id);
OldOid = ObjectId.BuildFromPtr(&delta->old_file.Id);
Exists = (delta->new_file.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;
OldExists = (delta->old_file.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;
Status = GetStatusFromChangeKind(delta->status);
}
// This treatment of change kind was apparently introduced in order to be able
// to compare a tree against the index, see commit fdc972b. It's extracted
// here so that TreeEntry can use the same rules without having to instantiate
// a TreeEntryChanges object.
internal static ChangeKind GetStatusFromChangeKind(ChangeKind changeKind)
{
switch (changeKind)
{
case ChangeKind.Untracked:
case ChangeKind.Ignored:
return ChangeKind.Added;
default:
return changeKind;
}
}
/// <summary>
/// The new path.
/// </summary>
public virtual string Path { get; private set; }
/// <summary>
/// The new <see cref="Mode"/>.
/// </summary>
public virtual Mode Mode { get; private set; }
/// <summary>
/// The new content hash.
/// </summary>
public virtual ObjectId Oid { get; private set; }
/// <summary>
/// The file exists in the new side of the diff.
/// This is useful in determining if you have content in
/// the ours or theirs side of a conflict. This will
/// be false during a conflict that deletes both the
/// "ours" and "theirs" sides, or when the diff is a
/// delete and the status is
/// <see cref="ChangeKind.Deleted"/>.
/// </summary>
public virtual bool Exists { get; private set; }
/// <summary>
/// The kind of change that has been done (added, deleted, modified ...).
/// </summary>
public virtual ChangeKind Status { get; private set; }
/// <summary>
/// The old path.
/// </summary>
public virtual string OldPath { get; private set; }
/// <summary>
/// The old <see cref="Mode"/>.
/// </summary>
public virtual Mode OldMode { get; private set; }
/// <summary>
/// The old content hash.
/// </summary>
public virtual ObjectId OldOid { get; private set; }
/// <summary>
/// The file exists in the old side of the diff.
/// This is useful in determining if you have an ancestor
/// side to a conflict. This will be false during a
/// conflict that involves both the "ours" and "theirs"
/// side being added, or when the diff is an add and the
/// status is <see cref="ChangeKind.Added"/>.
/// </summary>
public virtual bool OldExists { get; private set; }
private string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture,
"Path = {0}, File {1}",
!string.IsNullOrEmpty(Path)
? Path
: OldPath,
Status);
}
}
}
}