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
|
#include "config.h"
#include "branch.h"
#include <assert.h>
void branch_new(void){
int vid, nvid, noSign;
Stmt q;
char *zBranch, *zUuid, *zDate, *zComment, *zManifestFile;
const char *zColor;
Blob manifest;
Blob mcksum; /* Self-checksum on the manifest */
Blob cksum1, cksum2, dskcksum1; /* Before and after commit checksums */
Blob cksum1b; /* Checksum recorded in the manifest */
noSign = find_option("nosign","",0)!=0;
db_must_be_within_tree();
noSign = db_get_int("omit-ci-sig", 0)|noSign;
zColor = find_option("bgcolor","c",1);
verify_all_options();
/* fossil branch new name */
if( g.argc<3 ){
usage("branch new ?-bgcolor COLOR BRANCH-NAME");
}
zBranch = g.argv[3];
user_select();
db_begin_transaction();
if( unsaved_changes() ){
fossil_panic("there are uncommitted changes. please commit first");
}
/* Create a new rid? */
zManifestFile = mprintf("%smanifest", g.zLocalRoot);
blob_read_from_file(&manifest, zManifestFile);
free(zManifestFile);
zDate = db_text(0, "SELECT datetime('now')");
zDate[10] = 'T';
blob_appendf(&manifest, "D %s\n", zDate);
blob_appendf(&manifest, "T *%F *\n", zBranch);
md5sum_init();
md5sum_step_blob(&manifest);
md5sum_finish(&cksum1);
blob_reset(&manifest);
vid = db_lget_int("checkout", 0);
vfile_aggregate_checksum_disk(vid, &dskcksum1);
/* Create our new manifest */
blob_zero(&manifest);
zComment = mprintf("Branch created %s", zBranch);
blob_appendf(&manifest, "C %F\n", zComment);
blob_appendf(&manifest, "D %s\n", zDate);
db_prepare(&q,
"SELECT pathname, uuid FROM vfile JOIN blob ON vfile.mrid=blob.rid"
" WHERE NOT deleted AND vfile.vid=%d"
" ORDER BY 1", vid);
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
const char *zUuid = db_column_text(&q, 1);
blob_appendf(&manifest, "F %F %s\n", zName, zUuid);
}
db_finalize(&q);
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
blob_appendf(&manifest, "P %s\n", zUuid);
blob_appendf(&manifest, "R %b\n", &cksum1);
if( zColor!=0 ){
blob_appendf(&manifest, "T *bgcolor * %F\n", zColor);
}
blob_appendf(&manifest, "T *%F *\n", zBranch);
/* Cancel any tags that propagate */
db_prepare(&q,
"SELECT tagname"
" FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid"
" WHERE rid=%d AND tagtype=2", vid);
while( db_step(&q)==SQLITE_ROW ){
|
|
|
>
>
>
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
>
>
|
>
>
>
|
>
|
>
|
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
|
#include "config.h"
#include "branch.h"
#include <assert.h>
void branch_new(void){
int vid, nvid, noSign;
Stmt q;
char *zBranch, *zUuid, *zDate, *zComment;
const char *zColor;
Blob manifest;
Blob mcksum; /* Self-checksum on the manifest */
Blob cksum1, cksum2; /* Before and after commit checksums */
Blob cksum1b; /* Checksum recorded in the manifest */
noSign = find_option("nosign","",0)!=0;
db_must_be_within_tree();
noSign = db_get_int("omit-ci-sig", 0)|noSign;
zColor = find_option("bgcolor","c",1);
verify_all_options();
/* fossil branch new name */
if( g.argc<3 ){
usage("branch new ?-bgcolor COLOR BRANCH-NAME");
}
zBranch = g.argv[3];
if( zBranch==0 || zBranch[0]==0 ){
fossil_panic("branch name cannot be empty");
}
user_select();
db_begin_transaction();
if( unsaved_changes() ){
fossil_panic("there are uncommitted changes. please commit first");
}
vid = db_lget_int("checkout", 0);
vfile_aggregate_checksum_disk(vid, &cksum1);
/* Create our new manifest */
blob_zero(&manifest);
zComment = mprintf("Branch created %s", zBranch);
blob_appendf(&manifest, "C %F\n", zComment);
zDate = db_text(0, "SELECT datetime('now')");
zDate[10] = 'T';
blob_appendf(&manifest, "D %s\n", zDate);
db_prepare(&q,
"SELECT pathname, uuid FROM vfile JOIN blob ON vfile.mrid=blob.rid"
" WHERE NOT deleted AND vfile.vid=%d"
" ORDER BY 1", vid);
while( db_step(&q)==SQLITE_ROW ){
const char *zName = db_column_text(&q, 0);
const char *zUuid = db_column_text(&q, 1);
blob_appendf(&manifest, "F %F %s\n", zName, zUuid);
}
db_finalize(&q);
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
blob_appendf(&manifest, "P %s\n", zUuid);
blob_appendf(&manifest, "R %b\n", &cksum1);
if( zColor!=0 ){
if( strcmp("bgcolor",zBranch)>=0 ){
blob_appendf(&manifest, "T *%F *\n", zBranch);
blob_appendf(&manifest, "T *bgcolor * %F\n", zColor);
}else{
blob_appendf(&manifest, "T *bgcolor * %F\n", zColor);
blob_appendf(&manifest, "T *%F *\n", zBranch);
}
}else{
blob_appendf(&manifest, "T *%F *\n", zBranch);
}
/* Cancel any tags that propagate */
db_prepare(&q,
"SELECT tagname"
" FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid"
" WHERE rid=%d AND tagtype=2", vid);
while( db_step(&q)==SQLITE_ROW ){
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
if( nvid==0 ){
fossil_panic("trouble committing manifest: %s", g.zErrMsg);
}
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
manifest_crosslink(nvid, &manifest);
content_deltify(vid, nvid, 0);
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
printf("New_Version: %s\n", zUuid);
/* Verify that the manifest checksum matches the expected checksum */
vfile_aggregate_checksum_repository(nvid, &cksum2);
vfile_aggregate_checksum_manifest(nvid, &cksum2, &cksum1b);
if( blob_compare(&cksum1, &cksum1b) ){
fossil_panic("manifest checksum does not agree with manifest: "
"%b versus %b", &cksum1, &cksum1b);
}
/* Verify that the commit did not modify any disk images. */
vfile_aggregate_checksum_disk(vid, &cksum2);
if( blob_compare(&dskcksum1, &cksum2) ){
fossil_panic("tree checksums before and after commit do not match");
}
/* Clear the undo/redo stack */
undo_reset();
/* Commit */
|
|
>
>
>
>
>
>
|
|
128
129
130
131
132
133
134
135
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
|
if( nvid==0 ){
fossil_panic("trouble committing manifest: %s", g.zErrMsg);
}
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nvid);
manifest_crosslink(nvid, &manifest);
content_deltify(vid, nvid, 0);
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
printf("Branch Version: %s\n", zUuid);
printf("\n");
printf("Notice: working copy not updated to the new branch. If\n");
printf(" you wish to work on the new branch, update to\n");
printf(" that branch first:\n");
printf("\n");
printf(" fossil update %s\n", zBranch);
/* Verify that the manifest checksum matches the expected checksum */
vfile_aggregate_checksum_repository(nvid, &cksum2);
vfile_aggregate_checksum_manifest(nvid, &cksum2, &cksum1b);
if( blob_compare(&cksum1, &cksum1b) ){
fossil_panic("manifest checksum does not agree with manifest: "
"%b versus %b", &cksum1, &cksum1b);
}
/* Verify that the commit did not modify any disk images. */
vfile_aggregate_checksum_disk(vid, &cksum2);
if( blob_compare(&cksum1, &cksum2) ){
fossil_panic("tree checksums before and after commit do not match");
}
/* Clear the undo/redo stack */
undo_reset();
/* Commit */
|