︙ | | |
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
|
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
-
-
+
+
|
g.aCommitFile[jj++] = ii;
}
g.aCommitFile[jj] = 0;
bag_clear(&toCommit);
}
return result;
}
/*
** Returns true if the checkin identified by the first parameter is
** older than the given (valid) date/time string, else returns false.
** Also returns true if rid does not refer to a checkin, but it is not
** intended to be used for that case.
*/
static int checkin_is_younger(
int rid, /* The record ID of the ancestor */
const char *zDate /* Date & time of the current check-in */
){
return db_exists(
"SELECT 1 FROM event"
" WHERE datetime(mtime)>=%Q"
" AND type='ci' AND objid=%d",
zDate, rid
) ? 0 : 1;
}
/*
** Make sure the current check-in with timestamp zDate is younger than its
** ancestor identified rid and zUuid. Throw a fatal error if not.
*/
static void checkin_verify_younger(
int rid, /* The record ID of the ancestor */
const char *zUuid, /* The artifact ID of the ancestor */
const char *zDate /* Date & time of the current check-in */
){
#ifndef FOSSIL_ALLOW_OUT_OF_ORDER_DATES
int b;
b = db_exists(
"SELECT 1 FROM event"
" WHERE datetime(mtime)>=%Q"
" AND type='ci' AND objid=%d",
zDate, rid
if(checkin_is_younger(rid,zDate)==0){
);
if( b ){
fossil_fatal("ancestor check-in [%S] (%s) is not older (clock skew?)"
" Use --allow-older to override.", zUuid, zDate);
}
#endif
}
/*
** zDate should be a valid date string. Convert this string into the
** format YYYY-MM-DDTHH:MM:SS. If the string is not a valid date,
** print a fatal error and quit.
*/
char *date_in_standard_format(const char *zInputDate){
|
︙ | | |
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
|
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
|
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
/*
** By default, content containing what appears to be a merge conflict
** marker is not permitted. This flag relaxes that requirement.
*/
CIMINI_ALLOW_MERGE_MARKER = 1<<3,
/*
** By default mini-checkins are not allowed to be "older"
** than their parent. i.e. they may not have a timestamp
** which predates their parent. This flag bypasses that
** check.
*/
CIMINI_ALLOW_OLDER = 1<<4,
/*
** NOT YET IMPLEMENTED. A hint to checkin_mini() to prefer
** creation of a delta manifest.
*/
CIMINI_PREFER_DELTA = 1<<5,
/*
** NOT YET IMPLEMENTED.
*/
CIMINI_ALLOW_CLOSED_LEAF = 1<<4
CIMINI_ALLOW_CLOSED_LEAF = 1<<6
};
/*
** Creates a manifest file, written to pOut, from the state in the
** fully-populated pCI argument. pCI is not *semantically* modified
** but cannot be const because blob_str() may need to NUL-terminate
** any given blob.
|
︙ | | |
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
|
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
|
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
|
? fossil_strcmp
: fossil_stricmp;
assert(blob_str(&pCI->fileHash));
assert(pCI->pParent);
assert(pCI->zFilename);
assert(pCI->zUser);
assert(pCI->zDate);
#define mf_err(EXPR) if(pErr) blob_appendf EXPR; return 0
/* Potential TODOs include...
** - Create a delta manifest, if possible, rather than a baseline.
** - Maybe add support for tags. Those can be edited via /info page.
** - Symlinks: if we're really in a checkout, handle commit/add of
** symlinks like a normal commit would. For now we bail out if
** told to handle a symlink because there would seem to be no(?)
** sensible way to handle a symlink add/checkin without a
** checkout.
*/
blob_zero(pOut);
if(blob_size(&pCI->comment)!=0){
blob_appendf(pOut, "C %F\n", blob_str(&pCI->comment));
}else{
blob_append(pOut, "C (no\\scomment)\n", 16);
}
{
/*
** We don't use date_in_standard_format() because that has
** side-effects we don't want to trigger here.
*/
char * zDVal = db_text(
0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%f',%Q)",
pCI->zDate
? pCI->zDate
: "now");
if(zDVal[0]==0){
fossil_free(zDVal);
mf_err((pErr,
"Invalid date format (%s): use \"YYYY-MM-DD HH:MM:SS.SSS\"",
pCI->zDate));
}
blob_appendf(pOut, "D %z\n", zDVal);
blob_appendf(pOut, "D %z\n", pCI->zDate);
}
manifest_file_rewind(pCI->pParent);
while((zFile = manifest_file_next(pCI->pParent, 0))){
cmp = fncmp(zFile->zName, pCI->zFilename);
if(cmp<0){
blob_appendf(pOut, "F %F %s%s%s\n", zFile->zName, zFile->zUuid,
(zFile->zPerm && *zFile->zPerm) ? " " : "",
(zFile->zPerm && *zFile->zPerm) ? zFile->zPerm : "");
|
︙ | | |
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
|
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
|
+
+
-
-
-
+
+
+
+
+
+
+
+
+
|
** thus it cannot perform autosync or similar activities.
**
** This routine uses the state from the given fully-populated pCI
** argument to add pCI->fileContent to the database, and create and
** save a manifest for that change. Ownership of pCI and its contents
** are unchanged.
**
** pCI may be modified as follows:
**
** If pCI->fileHash is empty, this routine populates it with the
** repository's preferred hash algorithm. pCI is not otherwise
** modified, nor is its ownership modified.
** - If pCI->fileHash is empty, this routine populates it with the
** repository's preferred hash algorithm.
**
** - pCI->zDate is normalized to/replaced with a valid date/time
** string. If its original value cannot be validated then
** this function fails. If pCI->zDate is NULL, the current time
** is used.
**
** pCI's ownership is not modified.
**
** This function validates several of the inputs and fails if any
** validation fails.
**
** On error, returns false (0) and, if pErr is not NULL, writes a
** diagnostic message there.
**
|
︙ | | |
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
|
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
|
+
+
|
int ciminiFlags, Blob * pErr ){
Blob mf = empty_blob; /* output manifest */
int rid = 0, frid = 0; /* various RIDs */
const int isPrivate = content_is_private(pCI->pParent->rid);
ManifestFile * zFile; /* file from pCI->pParent */;
const char * zFilePrevUuid = 0; /* UUID of previous version of
the file */
#define ci_err(EXPR) if(pErr!=0){blob_appendf EXPR;} goto ci_error
db_begin_transaction();
if( !db_exists("SELECT 1 FROM user WHERE login=%Q", pCI->zUser) ){
ci_err((pErr,"No such user: %s", pCI->zUser));
}
assert(pCI->pParent->rid>0);
if(leaf_is_closed(pCI->pParent->rid)){
ci_err((pErr,"Cannot commit to a closed leaf."));
|
︙ | | |
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
|
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
ci_err((pErr,"Parent [%S] is not a leaf and forking is disabled.",
pCI->zParentUuid));
}
if(!(CIMINI_ALLOW_MERGE_MARKER & ciminiFlags)
&& contains_merge_marker(&pCI->fileContent)){
ci_err((pErr,"Content appears to contain a merge conflict marker."));
}
{
/*
** Normalize the timestamp. We don't use date_in_standard_format()
** because that has side-effects we don't want to trigger here.
*/
char * zDVal = db_text(
0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%f',%Q)",
pCI->zDate ? pCI->zDate : "now");
if(zDVal[0]==0){
fossil_free(zDVal);
ci_err((pErr,"Invalid timestamp string: %s", pCI->zDate));
}
fossil_free(pCI->zDate);
pCI->zDate = zDVal;
}
if(!(CIMINI_ALLOW_OLDER & ciminiFlags)
&& !checkin_is_younger(pCI->pParent->rid, pCI->zDate)){
ci_err((pErr,"Checkin time (%s) may not be older "
"than its parent (%z).",
pCI->zDate,
db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%f',%lf)",
pCI->pParent->rDate)
));
}
/* Potential TODOs include:
**
** - Commit allows an empty checkin only with a flag, but we
** currently disallow it entirely. Conform with commit?
**
** Non-TODOs:
**
** - Check for a commit lock would require auto-sync, which this
** code cannot do if it's going to be run via a web page.
*/
/*
** Confirm that pCI->zFilename can be found in pCI->pParent. If
|
︙ | | |
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
|
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
|
+
+
+
+
+
+
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
|
zFile = manifest_file_seek(pCI->pParent, pCI->zFilename, 0);
if(!zFile){
ci_err((pErr,"File [%s] not found in manifest [%S]. "
"Adding new files is currently not allowed.",
pCI->zFilename, pCI->zParentUuid));
}else if(zFile->zPerm && strstr(zFile->zPerm, "l")){
ci_err((pErr,"Cannot save a symlink this way."));
}
if(blob_size(&pCI->fileHash)==0){
/* Hash the content if it's not done already... */
hname_hash(&pCI->fileContent, 0, &pCI->fileHash);
assert(blob_size(&pCI->fileHash)>0);
}
}else{
if(zFile){
/* Has this file been changed since its previous commit? */
assert(blob_size(&pCI->fileHash));
if(0==fossil_strcmp(zFile->zUuid, blob_str(&pCI->fileHash))){
ci_err((pErr,"File is unchanged. Not saving."));
}
zFilePrevUuid = zFile->zUuid;
}
if(blob_size(&pCI->fileHash)==0){
hname_hash(&pCI->fileContent, 0, &pCI->fileHash);
assert(blob_size(&pCI->fileHash)>0);
}
/* Create the manifest... */
if(create_manifest_mini(&mf, pCI, pErr)==0){
return 0;
}
/* Save and deltify the file content... */
frid = content_put_ex(&pCI->fileContent, blob_str(&pCI->fileHash),
0, 0, isPrivate);
if(zFilePrevUuid!=0){
int prevFRid = fast_uuid_to_rid(zFilePrevUuid);
assert(prevFRid>0);
content_deltify(frid, &prevFRid, 1, 0);
}
/* Save, deltify, and crosslink the manifest... */
rid = content_put_ex(&mf, 0, 0, 0, isPrivate);
content_deltify(rid, &pCI->pParent->rid, 1, 0);
if(pRid!=0){
*pRid = rid;
}
if(ciminiFlags & CIMINI_DUMP_MANIFEST){
fossil_print("Manifest: %z\n%b", rid_to_uuid(rid), &mf);
fossil_print("Manifest %z:\n%b", rid_to_uuid(rid), &mf);
}
manifest_crosslink(rid, &mf, 0);
blob_reset(&mf);
db_end_transaction((CIMINI_DRY_RUN & ciminiFlags) ? 1 : 0);
if(pRid!=0){
*pRid = rid;
}
return 1;
ci_error:
assert(db_transaction_nesting_depth()>0);
db_end_transaction(1);
return 0;
#undef ci_err
}
|
︙ | | |
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
|
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
|
+
+
|
** --allow-fork Allows the commit to be made against a
** non-leaf parent. Note that no autosync
** is performed beforehand.
** --allow-merge-conflict Allows checkin of a file even if it appears
** to contain a fossil merge conflict marker.
** --user-override USER USER to use instead of the current default.
** --date-override DATETIME DATE to use instead of 'now'.
** --allow-older Allow a commit to be older than its
** ancestor.
** --dump-manifest|-d Dumps the generated manifest to stdout.
** --wet-run Disables the default dry-run mode.
**
** Example:
**
** %fossil test-ci-mini -R REPO -m ... -r foo --as src/myfile.c myfile.c
**
|
︙ | | |
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
|
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
|
+
+
+
|
ciminiFlags |= CIMINI_ALLOW_FORK;
}
if(find_option("dump-manifest","d",0)!=0){
ciminiFlags |= CIMINI_DUMP_MANIFEST;
}
if(find_option("allow-merge-conflict",0,0)!=0){
ciminiFlags |= CIMINI_ALLOW_MERGE_MARKER;
}
if(find_option("allow-older",0,0)!=0){
ciminiFlags |= CIMINI_ALLOW_OLDER;
}
db_find_and_open_repository(0, 0);
verify_all_options();
user_select();
if(g.argc!=3){
|
︙ | | |