Fossil SCM

Add additional metadata to patch files.

drh 2021-06-23 15:43 trunk
Commit b9d5fa4d7b73e311803577cc6bcd5d0054c289f69f316fcf289f79efbc3ba312
1 file changed +42 -1
+42 -1
--- src/patch.c
+++ src/patch.c
@@ -29,10 +29,29 @@
2929
# undef popen
3030
# define popen _popen
3131
# undef pclose
3232
# define pclose _pclose
3333
#endif
34
+
35
+/*
36
+** Try to compute the name of the computer on which this process
37
+** is running.
38
+*/
39
+char *fossil_hostname(void){
40
+ FILE *in;
41
+ char zBuf[200];
42
+ in = popen("hostname","r");
43
+ if( in ){
44
+ size_t n = fread(zBuf, 1, sizeof(zBuf)-1, in);
45
+ while( n>0 && fossil_isspace(zBuf[n-1]) ){ n--; }
46
+ if( n<0 ) n = 0;
47
+ zBuf[n] = 0;
48
+ pclose(in);
49
+ return fossil_strdup(zBuf);
50
+ }
51
+ return 0;
52
+}
3453
3554
/*
3655
** Flags passed from the main patch_cmd() routine into subfunctions used
3756
** to implement the various subcommands.
3857
*/
@@ -127,10 +146,11 @@
127146
** Generate a binary patch file and store it into the file
128147
** named zOut.
129148
*/
130149
void patch_create(const char *zOut, FILE *out){
131150
int vid;
151
+ char *z;
132152
133153
if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
134154
fossil_fatal("patch file already exists: %s", zOut);
135155
}
136156
add_content_sql_commands(g.db);
@@ -156,13 +176,34 @@
156176
" value ANY\n"
157177
");"
158178
);
159179
vid = db_lget_int("checkout", 0);
160180
vfile_check_signature(vid, CKSIG_ENOTFILE);
181
+ user_select();
161182
db_multi_exec(
162183
"INSERT INTO patch.cfg(key,value)"
163
- "SELECT 'baseline',uuid FROM blob WHERE rid=%d", vid);
184
+ "SELECT 'baseline',uuid FROM blob WHERE rid=%d "
185
+ "UNION ALL"
186
+ " SELECT 'ckout',rtrim(%Q,'/')"
187
+ "UNION ALL"
188
+ " SELECT 'repo',%Q "
189
+ "UNION ALL"
190
+ " SELECT 'user',%Q "
191
+ "UNION ALL"
192
+ " SELECT 'date',julianday('now')"
193
+ "UNION ALL"
194
+ " SELECT 'project-code',value FROM repository.config"
195
+ " WHERE name='project-code' "
196
+ "UNION ALL"
197
+ " SELECT 'fossil-date',julianday('" MANIFEST_DATE "')"
198
+ ";", vid, g.zLocalRoot, g.zRepositoryName, g.zLogin);
199
+ z = fossil_hostname();
200
+ if( z ){
201
+ db_multi_exec(
202
+ "INSERT INTO patch.cfg(key,value)VALUES('hostname',%Q)", z);
203
+ fossil_free(z);
204
+ }
164205
165206
/* New files */
166207
db_multi_exec(
167208
"INSERT INTO patch.chng(pathname,hash,isexe,islink,delta)"
168209
" SELECT pathname, NULL, isexe, islink,"
169210
--- src/patch.c
+++ src/patch.c
@@ -29,10 +29,29 @@
29 # undef popen
30 # define popen _popen
31 # undef pclose
32 # define pclose _pclose
33 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
35 /*
36 ** Flags passed from the main patch_cmd() routine into subfunctions used
37 ** to implement the various subcommands.
38 */
@@ -127,10 +146,11 @@
127 ** Generate a binary patch file and store it into the file
128 ** named zOut.
129 */
130 void patch_create(const char *zOut, FILE *out){
131 int vid;
 
132
133 if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
134 fossil_fatal("patch file already exists: %s", zOut);
135 }
136 add_content_sql_commands(g.db);
@@ -156,13 +176,34 @@
156 " value ANY\n"
157 ");"
158 );
159 vid = db_lget_int("checkout", 0);
160 vfile_check_signature(vid, CKSIG_ENOTFILE);
 
161 db_multi_exec(
162 "INSERT INTO patch.cfg(key,value)"
163 "SELECT 'baseline',uuid FROM blob WHERE rid=%d", vid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
165 /* New files */
166 db_multi_exec(
167 "INSERT INTO patch.chng(pathname,hash,isexe,islink,delta)"
168 " SELECT pathname, NULL, isexe, islink,"
169
--- src/patch.c
+++ src/patch.c
@@ -29,10 +29,29 @@
29 # undef popen
30 # define popen _popen
31 # undef pclose
32 # define pclose _pclose
33 #endif
34
35 /*
36 ** Try to compute the name of the computer on which this process
37 ** is running.
38 */
39 char *fossil_hostname(void){
40 FILE *in;
41 char zBuf[200];
42 in = popen("hostname","r");
43 if( in ){
44 size_t n = fread(zBuf, 1, sizeof(zBuf)-1, in);
45 while( n>0 && fossil_isspace(zBuf[n-1]) ){ n--; }
46 if( n<0 ) n = 0;
47 zBuf[n] = 0;
48 pclose(in);
49 return fossil_strdup(zBuf);
50 }
51 return 0;
52 }
53
54 /*
55 ** Flags passed from the main patch_cmd() routine into subfunctions used
56 ** to implement the various subcommands.
57 */
@@ -127,10 +146,11 @@
146 ** Generate a binary patch file and store it into the file
147 ** named zOut.
148 */
149 void patch_create(const char *zOut, FILE *out){
150 int vid;
151 char *z;
152
153 if( zOut && file_isdir(zOut, ExtFILE)!=0 ){
154 fossil_fatal("patch file already exists: %s", zOut);
155 }
156 add_content_sql_commands(g.db);
@@ -156,13 +176,34 @@
176 " value ANY\n"
177 ");"
178 );
179 vid = db_lget_int("checkout", 0);
180 vfile_check_signature(vid, CKSIG_ENOTFILE);
181 user_select();
182 db_multi_exec(
183 "INSERT INTO patch.cfg(key,value)"
184 "SELECT 'baseline',uuid FROM blob WHERE rid=%d "
185 "UNION ALL"
186 " SELECT 'ckout',rtrim(%Q,'/')"
187 "UNION ALL"
188 " SELECT 'repo',%Q "
189 "UNION ALL"
190 " SELECT 'user',%Q "
191 "UNION ALL"
192 " SELECT 'date',julianday('now')"
193 "UNION ALL"
194 " SELECT 'project-code',value FROM repository.config"
195 " WHERE name='project-code' "
196 "UNION ALL"
197 " SELECT 'fossil-date',julianday('" MANIFEST_DATE "')"
198 ";", vid, g.zLocalRoot, g.zRepositoryName, g.zLogin);
199 z = fossil_hostname();
200 if( z ){
201 db_multi_exec(
202 "INSERT INTO patch.cfg(key,value)VALUES('hostname',%Q)", z);
203 fossil_free(z);
204 }
205
206 /* New files */
207 db_multi_exec(
208 "INSERT INTO patch.chng(pathname,hash,isexe,islink,delta)"
209 " SELECT pathname, NULL, isexe, islink,"
210

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button