UNPKG

4.96 kBTypeScriptView Raw
1import { Blob } from "./blob";
2import { Buf } from "./buf";
3import { ConvenientPatch } from "./convenient-patch";
4import { DiffDelta } from "./diff-delta";
5import { DiffOptions } from "./diff-options";
6import { DiffPerfdata } from "./diff-perf-data";
7import { DiffStats } from "./diff-stats";
8import { Index } from "./index_";
9import { Repository } from "./repository";
10import { Strarray } from "./str-array";
11import { Tree } from "./tree";
12
13export interface DiffFindOptions {
14 version?: number | undefined;
15 flags?: number | undefined;
16 renameThreshold?: number | undefined;
17 renameFromRewriteThreshold?: number | undefined;
18 copyThreshold?: number | undefined;
19 breakRewriteThreshold?: number | undefined;
20 renameLimit?: number | undefined;
21}
22
23export namespace Diff {
24 const enum DELTA {
25 UNMODIFIED = 0,
26 ADDED = 1,
27 DELETED = 2,
28 MODIFIED = 3,
29 RENAMED = 4,
30 COPIED = 5,
31 IGNORED = 6,
32 UNTRACKED = 7,
33 TYPECHANGE = 8,
34 UNREADABLE = 9,
35 CONFLICTED = 10,
36 }
37
38 const enum FIND {
39 BY_CONFIG = 0,
40 RENAMES = 1,
41 RENAMES_FROM_REWRITES = 2,
42 COPIES = 4,
43 COPIES_FROM_UNMODIFIED = 8,
44 REWRITES = 16,
45 BREAK_REWRITES = 32,
46 AND_BREAK_REWRITES = 48,
47 FOR_UNTRACKED = 64,
48 ALL = 255,
49 IGNORE_LEADING_WHITESPACE = 0,
50 IGNORE_WHITESPACE = 4096,
51 DONT_IGNORE_WHITESPACE = 8192,
52 EXACT_MATCH_ONLY = 16384,
53 BREAK_REWRITES_FOR_RENAMES_ONLY = 32768,
54 REMOVE_UNMODIFIED = 65536,
55 }
56
57 const enum FLAG {
58 BINARY = 1,
59 NOT_BINARY = 2,
60 VALID_ID = 4,
61 EXISTS = 8,
62 }
63
64 const enum FORMAT {
65 PATCH = 1,
66 PATCH_HEADER = 2,
67 RAW = 3,
68 NAME_ONLY = 4,
69 NAME_STATUS = 5,
70 }
71
72 const enum FORMAT_EMAIL_FLAGS {
73 FORMAT_EMAIL_NONE = 0,
74 FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = 1,
75 }
76
77 const enum LINE {
78 CONTEXT = 32,
79 ADDITION = 43,
80 DELETION = 45,
81 CONTEXT_EOFNL = 61,
82 ADD_EOFNL = 62,
83 DEL_EOFNL = 60,
84 FILE_HDR = 70,
85 HUNK_HDR = 72,
86 BINARY = 66,
87 }
88
89 const enum OPTION {
90 NORMAL = 0,
91 REVERSE = 1,
92 INCLUDE_IGNORED = 2,
93 RECURSE_IGNORED_DIRS = 4,
94 INCLUDE_UNTRACKED = 8,
95 RECURSE_UNTRACKED_DIRS = 16,
96 INCLUDE_UNMODIFIED = 32,
97 INCLUDE_TYPECHANGE = 64,
98 INCLUDE_TYPECHANGE_TREES = 128,
99 IGNORE_FILEMODE = 256,
100 IGNORE_SUBMODULES = 512,
101 IGNORE_CASE = 1024,
102 INCLUDE_CASECHANGE = 2048,
103 DISABLE_PATHSPEC_MATCH = 4096,
104 SKIP_BINARY_CHECK = 8192,
105 ENABLE_FAST_UNTRACKED_DIRS = 16384,
106 UPDATE_INDEX = 32768,
107 INCLUDE_UNREADABLE = 65536,
108 INCLUDE_UNREADABLE_AS_UNTRACKED = 131072,
109 FORCE_TEXT = 1048576,
110 FORCE_BINARY = 2097152,
111 IGNORE_WHITESPACE = 4194304,
112 IGNORE_WHITESPACE_CHANGE = 8388608,
113 IGNORE_WHITESPACE_EOL = 16777216,
114 SHOW_UNTRACKED_CONTENT = 33554432,
115 SHOW_UNMODIFIED = 67108864,
116 PATIENCE = 268435456,
117 MINIMAL = 536870912,
118 SHOW_BINARY = 1073741824,
119 }
120
121 const enum STATS_FORMAT {
122 STATS_NONE = 0,
123 STATS_FULL = 1,
124 STATS_SHORT = 2,
125 STATS_NUMBER = 4,
126 STATS_INCLUDE_SUMMARY = 8,
127 }
128}
129
130export class Diff {
131 /**
132 * Directly run a diff between a blob and a buffer.
133 */
134 static blobToBuffer(
135 oldBlob?: Blob,
136 oldAsPath?: string,
137 buffer?: string,
138 bufferAsPath?: string,
139 opts?: DiffOptions,
140 fileCb?: Function,
141 binaryCb?: Function,
142 hunkCb?: Function,
143 lineCb?: Function,
144 ): Promise<any>;
145 static fromBuffer(content: string, contentLen: number): Promise<Diff>;
146 static indexToWorkdir(repo: Repository, index?: Index, opts?: DiffOptions): Promise<Diff>;
147 static indexToIndex(repo: Repository, oldIndex: Index, newIndex: Index, opts?: DiffOptions): Promise<Diff>;
148 static treeToIndex(repo: Repository, oldTree?: Tree, index?: Index, opts?: DiffOptions): Promise<Diff>;
149 static treeToTree(repo: Repository, oldTree?: Tree, new_tree?: Tree, opts?: DiffOptions): Promise<Diff>;
150 static treeToWorkdir(repo: Repository, oldTree?: Tree, opts?: DiffOptions): Promise<Diff>;
151 static treeToWorkdirWithIndex(repo: Repository, oldTree?: Tree, opts?: DiffOptions): Promise<Diff>;
152
153 findSimilar(options?: DiffFindOptions): Promise<number>;
154 getDelta(idx: number): DiffDelta;
155 getPerfdata(): Promise<DiffPerfdata>;
156 numDeltas(): number;
157 /**
158 * Retrieve patches in this difflist
159 */
160 patches(): Promise<ConvenientPatch[]>;
161 merge(from: Diff): Promise<number>;
162 toBuf(format: Diff.FORMAT): Promise<Buf>;
163
164 /**
165 * @returns - Structure containg the diff statistics.
166 */
167 getStats(): Promise<DiffStats>;
168}