-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathGTDiffDelta.h
More file actions
139 lines (121 loc) · 6.09 KB
/
GTDiffDelta.h
File metadata and controls
139 lines (121 loc) · 6.09 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// GTDiffDelta.h
// ObjectiveGitFramework
//
// Created by Danny Greg on 30/11/2012.
// Copyright (c) 2012 GitHub, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <git2/diff.h>
#import "GTDiffFile.h"
@class GTBlob;
@class GTDiff;
@class GTDiffHunk;
@class GTDiffPatch;
/// The type of change that this delta represents.
///
/// GTDiffFileDeltaUnmodified - No Change.
/// GTDiffFileDeltaAdded - The file was added to the index.
/// GTDiffFileDeltaDeleted - The file was removed from the working directory.
/// GTDiffFileDeltaModified - The file was modified.
/// GTDiffFileDeltaRenamed - The file has been renamed.
/// GTDiffFileDeltaCopied - The file was duplicated.
/// GTDiffFileDeltaIgnored - The file was ignored by git.
/// GTDiffFileDeltaUntracked - The file has been added to the working directory
/// and is therefore currently untracked.
/// GTDiffFileDeltaTypeChange - The file has changed from a blob to either a
/// submodule, symlink or directory. Or vice versa.
typedef NS_ENUM(NSInteger, GTDiffDeltaType) {
GTDiffFileDeltaUnmodified = GIT_DELTA_UNMODIFIED,
GTDiffFileDeltaAdded = GIT_DELTA_ADDED,
GTDiffFileDeltaDeleted = GIT_DELTA_DELETED,
GTDiffFileDeltaModified = GIT_DELTA_MODIFIED,
GTDiffFileDeltaRenamed = GIT_DELTA_RENAMED,
GTDiffFileDeltaCopied = GIT_DELTA_COPIED,
GTDiffFileDeltaIgnored = GIT_DELTA_IGNORED,
GTDiffFileDeltaUntracked = GIT_DELTA_UNTRACKED,
GTDiffFileDeltaTypeChange = GIT_DELTA_TYPECHANGE,
};
NS_ASSUME_NONNULL_BEGIN
/// A class representing a single change within a diff.
///
/// The change may not be simply a change of text within a given file, it could
/// be that the file was renamed, or added to the index. See `GTDiffDeltaType`
/// for the types of change represented.
@interface GTDiffDelta : NSObject
/// The `git_diff_delta` represented by the receiver.
@property (nonatomic, assign, readonly) git_diff_delta git_diff_delta;
/// Any flags set on the delta. See `GTDiffFileFlag` for more info.
///
/// Note that this may not include `GTDiffFileFlagBinary` _or_
/// `GTDiffFileFlagNotBinary` until the content is loaded for this delta (e.g.,
/// through a call to -generatePatch:).
@property (nonatomic, assign, readonly) GTDiffFileFlag flags;
/// The file to the "left" of the diff.
@property (nonatomic, readonly, copy) GTDiffFile *oldFile;
/// The file to the "right" of the diff.
@property (nonatomic, readonly, copy) GTDiffFile *newFile __attribute__((ns_returns_not_retained));
/// The type of change that this delta represents.
///
/// Think "status" as in `git status`.
@property (nonatomic, readonly) GTDiffDeltaType type;
/// Diffs the given blob and data buffer.
///
/// oldBlob - The blob which should comprise the left side of the diff. May be
/// nil to represent an empty blob.
/// oldBlobPath - The path to which `oldBlob` corresponds. May be nil.
/// newBlob - The blob which should comprise the right side of the diff. May be
/// nil to represent an empty blob.
/// newBlobPath - The path to which `newBlob` corresponds. May be nil.
/// options - A dictionary containing any of the above options key constants,
// or nil to use the defaults.
/// error - If not NULL, set to any error that occurs.
///
/// Returns a diff delta, or nil if an error occurs.
+ (nullable instancetype)diffDeltaFromBlob:(nullable GTBlob *)oldBlob forPath:(nullable NSString *)oldBlobPath toBlob:(nullable GTBlob *)newBlob forPath:(nullable NSString *)newBlobPath options:(nullable NSDictionary *)options error:(NSError **)error;
/// Diffs the given blob and data buffer.
///
/// blob - The blob which should comprise the left side of the diff. May be
/// nil to represent an empty blob.
/// blobPath - The path to which `blob` corresponds. May be nil.
/// data - The data which should comprise the right side of the diff. May be
/// nil to represent an empty blob.
/// dataPath - The path to which `data` corresponds. May be nil.
/// options - A dictionary containing any of the above options key constants,
// or nil to use the defaults.
/// error - If not NULL, set to any error that occurs.
///
/// Returns a diff delta, or nil if an error occurs.
+ (nullable instancetype)diffDeltaFromBlob:(nullable GTBlob *)blob forPath:(nullable NSString *)blobPath toData:(nullable NSData *)data forPath:(nullable NSString *)dataPath options:(nullable NSDictionary *)options error:(NSError **)error;
/// Diffs the given data buffers.
///
/// oldData - The data which should comprise the left side of the diff. May be
/// nil to represent an empty blob.
/// oldDataPath - The path to which `oldData` corresponds. May be nil.
/// newData - The data which should comprise the right side of the diff. May
/// be nil to represent an empty blob.
/// newDataPath - The path to which `newData` corresponds. May be nil.
/// options - A dictionary containing any of the above options key constants,
// or nil to use the defaults.
/// error - If not NULL, set to any error that occurs.
///
/// Returns a diff delta, or nil if an error occurs.
+ (nullable instancetype)diffDeltaFromData:(nullable NSData *)oldData forPath:(nullable NSString *)oldDataPath toData:(nullable NSData *)newData forPath:(nullable NSString *)newDataPath options:(nullable NSDictionary *)options error:(NSError **)error;
- (instancetype)init NS_UNAVAILABLE;
/// Initializes the receiver to wrap the delta at the given index.
///
/// diff - The diff which contains the delta to wrap. Must not be nil.
/// deltaIndex - The index of the delta within the diff.
///
/// Returns a diff delta, or nil if an error occurs.
- (nullable instancetype)initWithDiff:(GTDiff *)diff deltaIndex:(NSUInteger)deltaIndex;
/// Creates a patch from a text delta.
///
/// If the receiver represents a binary delta, this method will return an error.
///
/// error - If not NULL, set to any error that occurs.
///
/// Returns a new patch, or nil if an error occurs.
- (nullable GTDiffPatch *)generatePatch:(NSError **)error;
@end
NS_ASSUME_NONNULL_END