| ︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date.
** If the input is of the form "date:*" or "localtime:*" or "utc:*" then
** always resolve the name as a date.
**
** Return 0 on success. Return 1 if the name cannot be resolved.
** Return 2 name is ambiguous.
*/
int name_to_uuid(Blob *pName, int iErrPriority){
int name_to_uuid(Blob *pName, int iErrPriority, const char *zType){
int rc;
int sz;
sz = blob_size(pName);
if( sz>UUID_SIZE || sz<4 || !validate16(blob_buffer(pName), sz) ){
char *zUuid;
const char *zName = blob_str(pName);
if( memcmp(zName, "tag:", 4)==0 ){
zName += 4;
zUuid = tag_to_uuid(zName);
zUuid = tag_to_uuid(zName, zType);
}else{
zUuid = tag_to_uuid(zName);
zUuid = tag_to_uuid(zName, zType);
if( zUuid==0 ){
zUuid = date_to_uuid(zName);
zUuid = date_to_uuid(zName, zType);
}
}
if( zUuid ){
blob_reset(pName);
blob_append(pName, zUuid, -1);
free(zUuid);
return 0;
|
| ︙ | | |
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
-
+
|
}
}else if( sz<UUID_SIZE && sz>=4 ){
Stmt q;
db_prepare(&q, "SELECT uuid FROM blob WHERE uuid GLOB '%b*'", pName);
if( db_step(&q)!=SQLITE_ROW ){
char *zUuid;
db_finalize(&q);
zUuid = tag_to_uuid(blob_str(pName));
zUuid = tag_to_uuid(blob_str(pName), "*");
if( zUuid ){
blob_reset(pName);
blob_append(pName, zUuid, -1);
free(zUuid);
return 0;
}
fossil_error(iErrPriority, "no artifacts match the prefix \"%b\"", pName);
|
| ︙ | | |
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
|
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
|
-
+
-
-
+
+
+
+
+
-
+
|
** not older than 'date'.
**
** An input of "tip" returns the most recent check-in.
**
** Memory to hold the returned string comes from malloc() and needs to
** be freed by the caller.
*/
char *tag_to_uuid(const char *zTag){
char *tag_to_uuid(const char *zTag, const char *zType){
int vid;
char *zUuid =
db_text(0,
char *zUuid;
if( zType==0 || zType[0]==0 ) zType = "*";
zUuid = db_text(0,
"SELECT blob.uuid"
" FROM tag, tagxref, event, blob"
" WHERE tag.tagname='sym-%q' "
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
" AND event.objid=tagxref.rid "
" AND blob.rid=event.objid "
" AND event.type GLOB '%q'"
" ORDER BY event.mtime DESC ",
zTag
zTag, zType
);
if( zUuid==0 ){
int nTag = strlen(zTag);
int i;
for(i=0; i<nTag-10; i++){
if( zTag[i]==':' && is_date(&zTag[i+1]) ){
char *zDate = mprintf("%s", &zTag[i+1]);
|
| ︙ | | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
+
-
+
|
"SELECT blob.uuid"
" FROM tag, tagxref, event, blob"
" WHERE tag.tagname='sym-%q' "
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
" AND event.objid=tagxref.rid "
" AND blob.rid=event.objid "
" AND event.mtime<=julianday(%Q %s)"
" AND event.type GLOB '%q'"
" ORDER BY event.mtime DESC ",
zTagBase, zDate, (useUtc ? "" : ",'utc'")
zTagBase, zDate, (useUtc ? "" : ",'utc'"), zType
);
break;
}
}
if( zUuid==0 && fossil_strcmp(zTag, "tip")==0 ){
zUuid = db_text(0,
"SELECT blob.uuid"
|
| ︙ | | |
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
-
+
|
** date:DATE
** local:DATE
** utc:DATE
**
** The DATE is interpreted as localtime unless the "utc:" prefix is used
** or a "utc" string appears at the end of the DATE string.
*/
char *date_to_uuid(const char *zDate){
char *date_to_uuid(const char *zDate, const char *zType){
int useUtc = 0;
int n;
char *zCopy = 0;
char *zUuid;
if( memcmp(zDate, "date:", 5)==0 ){
zDate += 5;
|
| ︙ | | |
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
+
-
+
-
+
-
+
-
+
-
+
+
+
+
|
if( n>4 && sqlite3_strnicmp(&zDate[n-3], "utc", 3)==0 ){
zCopy = mprintf("%s", zDate);
zCopy[n-3] = 0;
zDate = zCopy;
n -= 3;
useUtc = 1;
}
if( zType==0 || zType[0]==0 ) zType = "*";
zUuid = db_text(0,
"SELECT (SELECT uuid FROM blob WHERE rid=event.objid)"
" FROM event"
" WHERE mtime<=julianday(%Q %s) AND type='ci'"
" WHERE mtime<=julianday(%Q %s) AND type GLOB '%q'"
" ORDER BY mtime DESC LIMIT 1",
zDate, useUtc ? "" : ",'utc'"
zDate, useUtc ? "" : ",'utc'", zType
);
free(zCopy);
return zUuid;
}
/*
** COMMAND: test-name-to-id
**
** Convert a name to a full artifact ID.
*/
void test_name_to_id(void){
int i;
Blob name;
db_must_be_within_tree();
for(i=2; i<g.argc; i++){
blob_init(&name, g.argv[i], -1);
fossil_print("%s -> ", g.argv[i]);
if( name_to_uuid(&name, 1) ){
if( name_to_uuid(&name, 1, "*") ){
fossil_print("ERROR: %s\n", g.zErrMsg);
fossil_error_reset();
}else{
fossil_print("%s\n", blob_buffer(&name));
}
blob_reset(&name);
}
}
/*
** Convert a name to a rid. If the name is a small integer value then
** just use atoi() to do the conversion. If the name contains alphabetic
** characters or is not an existing rid, then use name_to_uuid then
** convert the uuid to a rid.
**
** This routine is used by command-line routines to resolve command-line inputs
** into a rid.
*/
int name_to_rid(const char *zName){
int name_to_typed_rid(const char *zName, const char *zType){
int i;
int rid;
Blob name;
if( zName==0 || zName[0]==0 ) return 0;
blob_init(&name, zName, -1);
if( name_to_uuid(&name, -1) ){
if( name_to_uuid(&name, -1, zType) ){
blob_reset(&name);
for(i=0; zName[i] && fossil_isdigit(zName[i]); i++){}
if( zName[i]==0 ){
rid = atoi(zName);
if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){
return rid;
}
}
fossil_error(1, "no such artifact: %s", zName);
return 0;
}else{
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
blob_reset(&name);
}
return rid;
}
int name_to_rid(const char *zName){
return name_to_typed_rid(zName, "*");
}
/*
** WEBPAGE: ambiguous
** URL: /ambiguous?name=UUID&src=WEBPAGE
**
** The UUID given by the name paramager is ambiguous. Display a page
** that shows all possible choices and let the user select between them.
|
| ︙ | | |
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
-
+
|
int i, rc;
int rid;
const char *zName = P(zParamName);
Blob name;
if( zName==0 || zName[0]==0 ) return 0;
blob_init(&name, zName, -1);
rc = name_to_uuid(&name, -1);
rc = name_to_uuid(&name, -1, "*");
if( rc==1 ){
blob_reset(&name);
for(i=0; zName[i] && fossil_isdigit(zName[i]); i++){}
if( zName[i]==0 ){
rid = atoi(zName);
if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){
return rid;
|
| ︙ | | |