| ︙ | | |
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
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
** State information about an on-going fast-import parse.
*/
static struct {
void (*xFinish)(void); /* Function to finish a prior record */
int nData; /* Bytes of data */
char *zTag; /* Name of a tag */
char *zBranch; /* Name of a branch for a commit */
char *zPrevBranch; /* The branch of the previous check-in */
char *aData; /* Data content */
char *zMark; /* The current mark */
char *zDate; /* Date/time stamp */
char *zUser; /* User name */
char *zComment; /* Comment of a commit */
char *zFrom; /* from value as a UUID */
char *zPrevCheckin; /* Name of the previous check-in */
char *zFromMark; /* The mark of the "from" field */
int nMerge; /* Number of merge values */
int nMergeAlloc; /* Number of slots in azMerge[] */
char **azMerge; /* Merge values */
int nFile; /* Number of aFile values */
int nFileAlloc; /* Number of slots in aFile[] */
ImportFile *aFile; /* Information about files in a commit */
int fromLoaded; /* True zFrom content loaded into aFile[] */
} gg;
/*
** Duplicate a string.
*/
static char *import_strdup(const char *zOrig){
char *z = 0;
if( zOrig ){
int n = strlen(zOrig);
z = fossil_malloc( n+1 );
memcpy(z, zOrig, n+1);
}
return z;
}
/*
** A no-op "xFinish" method
*/
static void finish_noop(void){}
/*
|
| ︙ | | |
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
|
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
|
+
+
+
+
+
-
+
|
fossil_free(gg.aFile[i].zName);
fossil_free(gg.aFile[i].zUuid);
fossil_free(gg.aFile[i].zPrior);
}
memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
gg.nFile = 0;
if( freeAll ){
fossil_free(gg.zPrevBranch);
fossil_free(gg.zPrevCheckin);
fossil_free(gg.azMerge);
fossil_free(gg.aFile);
memset(&gg, 0, sizeof(gg));
}
gg.xFinish = finish_noop;
}
/*
** Insert an artifact into the BLOB table if it isn't there already.
** If zMark is not zero, create a cross-reference from that mark back
** to the newly inserted artifact.
**
** If saveUuid is true, then pContent is a commit record. Record its
** UUID in gg.zPrevCheckin.
*/
static int fast_insert_content(Blob *pContent, const char *zMark){
static int fast_insert_content(Blob *pContent, const char *zMark, int saveUuid){
Blob hash;
Blob cmpr;
int rid;
sha1sum_blob(pContent, &hash);
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &hash);
if( rid==0 ){
|
| ︙ | | |
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
+
+
+
+
-
+
-
+
|
);
db_multi_exec(
"INSERT INTO xtag(tname, trid, tuuid)"
"VALUES(%B,%d,%B)",
&hash, rid, &hash
);
}
if( saveUuid ){
fossil_free(gg.zPrevCheckin);
gg.zPrevCheckin = import_strdup(blob_str(&hash));
}
blob_reset(&hash);
return rid;
}
/*
** Use data accumulated in gg from a "blob" record to add a new file
** to the BLOB table.
*/
static void finish_blob(void){
Blob content;
blob_init(&content, gg.aData, gg.nData);
fast_insert_content(&content, gg.zMark);
fast_insert_content(&content, gg.zMark, 0);
blob_reset(&content);
import_reset(0);
}
/*
** Use data accumulated in gg from a "tag" record to add a new
** control artifact to the BLOB table.
*/
static void finish_tag(void){
Blob record, cksum;
if( gg.zDate && gg.zTag && gg.zFrom && gg.zUser ){
blob_zero(&record);
blob_appendf(&record, "D %s\n", gg.zDate);
blob_appendf(&record, "T +%F %s\n", gg.zTag, gg.zFrom);
blob_appendf(&record, "U %F\n", gg.zUser);
md5sum_blob(&record, &cksum);
blob_appendf(&record, "Z %b\n", &cksum);
fast_insert_content(&record, 0);
fast_insert_content(&record, 0, 0);
blob_reset(&record);
blob_reset(&cksum);
}
import_reset(0);
}
/*
|
| ︙ | | |
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
+
+
+
+
+
+
|
** Use data accumulated in gg from a "commit" record to add a new
** manifest artifact to the BLOB table.
*/
static void finish_commit(void){
int i;
char *zFromBranch;
Blob record, cksum;
if( gg.zFrom==0 && gg.zPrevCheckin!=0
&& fossil_strcmp(gg.zBranch, gg.zPrevBranch)==0
){
gg.zFrom = gg.zPrevCheckin;
gg.zPrevCheckin = 0;
}
import_prior_files();
qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
blob_zero(&record);
blob_appendf(&record, "C %F\n", gg.zComment);
blob_appendf(&record, "D %s\n", gg.zDate);
for(i=0; i<gg.nFile; i++){
const char *zUuid = gg.aFile[i].zUuid;
|
| ︙ | | |
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
-
+
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
|
blob_appendf(&record, "T +sym-trunk *\n");
}
db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)",
gg.zMark, gg.zBranch);
blob_appendf(&record, "U %F\n", gg.zUser);
md5sum_blob(&record, &cksum);
blob_appendf(&record, "Z %b\n", &cksum);
fast_insert_content(&record, gg.zMark);
fast_insert_content(&record, gg.zMark, 1);
blob_reset(&record);
blob_reset(&cksum);
import_reset(0);
fossil_free(gg.zPrevBranch);
gg.zPrevBranch = gg.zBranch;
gg.zBranch = 0;
import_reset(0);
}
/*
** Turn the first \n in the input string into a \000
*/
static void trim_newline(char *z){
while( z[0] && z[0]!='\n' ){ z++; }
z[0] = 0;
}
/*
** Duplicate a string.
*/
static char *import_strdup(const char *zOrig){
char *z = 0;
if( zOrig ){
int n = strlen(zOrig);
z = fossil_malloc( n+1 );
memcpy(z, zOrig, n+1);
}
return z;
}
/*
** Get a token from a line of text. Return a pointer to the first
** character of the token and zero-terminate the token. Make
** *pzIn point to the first character past the end of the zero
** terminator, or at the zero-terminator at EOL.
*/
static char *next_token(char **pzIn){
|
| ︙ | | |