rcsfile.c (185811) | rcsfile.c (186700) |
---|---|
1/*- 2 * Copyright (c) 2007-2008, Ulf Lilleengen <lulf@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2007-2008, Ulf Lilleengen <lulf@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: projects/csup_cvsmode/contrib/csup/rcsfile.c 185811 2008-12-09 21:10:09Z lulf $ | 26 * $FreeBSD: projects/csup_cvsmode/contrib/csup/rcsfile.c 186700 2009-01-02 12:40:58Z lulf $ |
27 */ 28 29#include <assert.h> 30#include <err.h> 31#include <errno.h> 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> --- 79 unchanged lines hidden (view full) --- 114 char *branch; /* Default branch. */ 115 char *cvsroot; 116 char *colltag; 117 STAILQ_HEAD(, string) accesslist; 118 STAILQ_HEAD(, tag) taglist; 119 int strictlock; 120 char *comment; 121 int expand; | 27 */ 28 29#include <assert.h> 30#include <err.h> 31#include <errno.h> 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> --- 79 unchanged lines hidden (view full) --- 114 char *branch; /* Default branch. */ 115 char *cvsroot; 116 char *colltag; 117 STAILQ_HEAD(, string) accesslist; 118 STAILQ_HEAD(, tag) taglist; 119 int strictlock; 120 char *comment; 121 int expand; |
122 int ro; |
|
122 struct branch *trunk; /* The tip delta. */ 123 124 LIST_HEAD(, delta) deltatable; 125 LIST_HEAD(, delta) deltatable_dates; 126 127 char *desc; 128}; 129 --- 18 unchanged lines hidden (view full) --- 148const char *branch_space = "\t"; 149const char *tag_space = "\t"; 150const char *date_space = "\t"; 151const char *auth_space = "\t"; 152const char *state_space = "\t"; 153const char *next_space = "\t"; 154const char *branches_space = "\t"; 155const char *comment_space ="\t"; | 123 struct branch *trunk; /* The tip delta. */ 124 125 LIST_HEAD(, delta) deltatable; 126 LIST_HEAD(, delta) deltatable_dates; 127 128 char *desc; 129}; 130 --- 18 unchanged lines hidden (view full) --- 149const char *branch_space = "\t"; 150const char *tag_space = "\t"; 151const char *date_space = "\t"; 152const char *auth_space = "\t"; 153const char *state_space = "\t"; 154const char *next_space = "\t"; 155const char *branches_space = "\t"; 156const char *comment_space ="\t"; |
157const char *expand_space = "\t"; |
|
156 157void print_stream(struct stream *); 158 159/* Print the contents of a stream, for debugging. */ 160void 161print_stream(struct stream *s) 162{ 163 char *line; --- 5 unchanged lines hidden (view full) --- 169 } 170 lprintf(-1, "\n"); 171} 172 173/* 174 * Parse rcsfile from path and return a pointer to it. 175 */ 176struct rcsfile * | 158 159void print_stream(struct stream *); 160 161/* Print the contents of a stream, for debugging. */ 162void 163print_stream(struct stream *s) 164{ 165 char *line; --- 5 unchanged lines hidden (view full) --- 171 } 172 lprintf(-1, "\n"); 173} 174 175/* 176 * Parse rcsfile from path and return a pointer to it. 177 */ 178struct rcsfile * |
177rcsfile_frompath(char *path, char *name, char *cvsroot, char *colltag) | 179rcsfile_frompath(char *path, char *name, char *cvsroot, char *colltag, int ro) |
178{ 179 struct rcsfile *rf; 180 FILE *infp; 181 int error; 182 183 if (path == NULL || name == NULL || cvsroot == NULL || colltag == NULL) 184 return (NULL); 185 --- 15 unchanged lines hidden (view full) --- 201 202 /* Initialize all fields. */ 203 rf->head = NULL; 204 rf->branch = NULL; 205 rf->strictlock = 0; 206 rf->comment = NULL; 207 rf->expand = EXPAND_DEFAULT; 208 rf->desc = NULL; | 180{ 181 struct rcsfile *rf; 182 FILE *infp; 183 int error; 184 185 if (path == NULL || name == NULL || cvsroot == NULL || colltag == NULL) 186 return (NULL); 187 --- 15 unchanged lines hidden (view full) --- 203 204 /* Initialize all fields. */ 205 rf->head = NULL; 206 rf->branch = NULL; 207 rf->strictlock = 0; 208 rf->comment = NULL; 209 rf->expand = EXPAND_DEFAULT; 210 rf->desc = NULL; |
211 rf->ro = ro; |
|
209 210 infp = fopen(path, "r"); 211 if (infp == NULL) { 212 lprintf(-1, "Cannot open \"%s\": %s\n", path, strerror(errno)); 213 rcsfile_free(rf); 214 return (NULL); 215 } | 212 213 infp = fopen(path, "r"); 214 if (infp == NULL) { 215 lprintf(-1, "Cannot open \"%s\": %s\n", path, strerror(errno)); 216 rcsfile_free(rf); 217 return (NULL); 218 } |
216 error = rcsparse_run(rf, infp); | 219 error = rcsparse_run(rf, infp, ro); |
217 fclose(infp); 218 if (error) { 219 lprintf(-1, "Error parsing \"%s\"\n", name); 220 rcsfile_free(rf); 221 return (NULL); 222 } 223 return (rf); 224} --- 113 unchanged lines hidden (view full) --- 338 stream_printf(dest, "locks;"); 339 if (rf->strictlock) 340 stream_printf(dest, " strict;"); 341 stream_printf(dest, "\n"); 342 343 /* Write out the comment. */ 344 if (rf->comment != NULL) 345 stream_printf(dest, "comment%s%s;\n", comment_space, rf->comment); | 220 fclose(infp); 221 if (error) { 222 lprintf(-1, "Error parsing \"%s\"\n", name); 223 rcsfile_free(rf); 224 return (NULL); 225 } 226 return (rf); 227} --- 113 unchanged lines hidden (view full) --- 341 stream_printf(dest, "locks;"); 342 if (rf->strictlock) 343 stream_printf(dest, " strict;"); 344 stream_printf(dest, "\n"); 345 346 /* Write out the comment. */ 347 if (rf->comment != NULL) 348 stream_printf(dest, "comment%s%s;\n", comment_space, rf->comment); |
349 if (rf->expand != EXPAND_DEFAULT) 350 stream_printf(dest, "expand%s@%s@;\n", expand_space, 351 keyword_encode_expand(rf->expand)); |
|
346 347 stream_printf(dest, "\n\n"); 348 349 /* 350 * Write out deltas. We use a stack where we push the appropriate deltas 351 * that is to be written out during the loop. 352 */ 353 STAILQ_INIT(&deltastack); --- 335 unchanged lines hidden (view full) --- 689 lprintf(1, "rev: %s", t->revnum); 690 lprintf(1, "\n"); 691 } 692 693 if (rf->strictlock) 694 lprintf(1, "Strict!\n"); 695 if (rf->comment != NULL) 696 lprintf(1, "comment: '%s'\n", rf->comment); | 352 353 stream_printf(dest, "\n\n"); 354 355 /* 356 * Write out deltas. We use a stack where we push the appropriate deltas 357 * that is to be written out during the loop. 358 */ 359 STAILQ_INIT(&deltastack); --- 335 unchanged lines hidden (view full) --- 695 lprintf(1, "rev: %s", t->revnum); 696 lprintf(1, "\n"); 697 } 698 699 if (rf->strictlock) 700 lprintf(1, "Strict!\n"); 701 if (rf->comment != NULL) 702 lprintf(1, "comment: '%s'\n", rf->comment); |
697 if (rf->expand >= 0) | 703 if (rf->expand != EXPAND_DEFAULT); |
698 lprintf(1, "expand: '%s'\n", keyword_encode_expand(rf->expand)); 699 700 /* Print all deltas. */ 701 LIST_FOREACH(d, &rf->deltatable, table_next) { 702 lprintf(1, "Delta: "); 703 if (d->revdate != NULL) 704 lprintf(1, "date: %s ", d->revdate); 705 if (d->revnum != NULL) --- 58 unchanged lines hidden (view full) --- 764 } 765 766 if (rf->comment != NULL) 767 free(rf->comment); 768 769 /* Free all deltas in global list */ 770 while (!LIST_EMPTY(&rf->deltatable)) { 771 d = LIST_FIRST(&rf->deltatable); | 704 lprintf(1, "expand: '%s'\n", keyword_encode_expand(rf->expand)); 705 706 /* Print all deltas. */ 707 LIST_FOREACH(d, &rf->deltatable, table_next) { 708 lprintf(1, "Delta: "); 709 if (d->revdate != NULL) 710 lprintf(1, "date: %s ", d->revdate); 711 if (d->revnum != NULL) --- 58 unchanged lines hidden (view full) --- 770 } 771 772 if (rf->comment != NULL) 773 free(rf->comment); 774 775 /* Free all deltas in global list */ 776 while (!LIST_EMPTY(&rf->deltatable)) { 777 d = LIST_FIRST(&rf->deltatable); |
772 LIST_REMOVE(d, delta_next); | 778 if (!rf->ro) 779 LIST_REMOVE(d, delta_next); |
773 LIST_REMOVE(d, table_next); 774 rcsfile_freedelta(d); 775 } 776 777 /* Free global branch. */ 778 if (rf->trunk->revnum != NULL) 779 free(rf->trunk->revnum); 780 free(rf->trunk); --- 85 unchanged lines hidden (view full) --- 866 * will tell us to delete the tags involved. 867 */ 868void 869rcsfile_deleterev(struct rcsfile *rf, char *revname) 870{ 871 struct delta *d; 872 873 d = rcsfile_getdelta(rf, revname); | 780 LIST_REMOVE(d, table_next); 781 rcsfile_freedelta(d); 782 } 783 784 /* Free global branch. */ 785 if (rf->trunk->revnum != NULL) 786 free(rf->trunk->revnum); 787 free(rf->trunk); --- 85 unchanged lines hidden (view full) --- 873 * will tell us to delete the tags involved. 874 */ 875void 876rcsfile_deleterev(struct rcsfile *rf, char *revname) 877{ 878 struct delta *d; 879 880 d = rcsfile_getdelta(rf, revname); |
874 LIST_REMOVE(d, delta_next); | 881 if (!rf->ro) 882 LIST_REMOVE(d, delta_next); |
875 LIST_REMOVE(d, table_next); 876 rcsfile_freedelta(d); 877} 878 879/* Delete a tag from the tag list. */ 880void 881rcsfile_deletetag(struct rcsfile *rf, char *tag, char *revnum) 882{ --- 177 unchanged lines hidden (view full) --- 1060 /* If we have a next, create a placeholder for it. */ 1061 if (next != NULL) { 1062 d_next = rcsfile_createdelta(next); 1063 d_next->placeholder = 1; 1064 /* Diffbase should be the previous. */ 1065 d_next->diffbase = d; 1066 } 1067 | 883 LIST_REMOVE(d, table_next); 884 rcsfile_freedelta(d); 885} 886 887/* Delete a tag from the tag list. */ 888void 889rcsfile_deletetag(struct rcsfile *rf, char *tag, char *revnum) 890{ --- 177 unchanged lines hidden (view full) --- 1068 /* If we have a next, create a placeholder for it. */ 1069 if (next != NULL) { 1070 d_next = rcsfile_createdelta(next); 1071 d_next->placeholder = 1; 1072 /* Diffbase should be the previous. */ 1073 d_next->diffbase = d; 1074 } 1075 |
1076 /* If we're opening read-only, do minimal work. */ 1077 if (rf->ro) { 1078 if (!d->placeholder) 1079 rcsfile_insertsorteddelta(rf, d); 1080 else 1081 d->placeholder = 0; 1082 if (d_next != NULL) 1083 rcsfile_insertsorteddelta(rf, d_next); 1084 return; 1085 } 1086 |
|
1068 /* If it's trunk, insert it in the head branch list. */ 1069 b = rcsrev_istrunk(d->revnum) ? rf->trunk : rcsfile_getbranch(rf, 1070 d->revnum); 1071 1072 /* 1073 * We didn't find a branch, check if we can find a branchpoint and 1074 * create a branch there. 1075 */ --- 71 unchanged lines hidden (view full) --- 1147 free(branchrev); 1148 return (b); 1149 } 1150 } 1151 free(branchrev); 1152 return (NULL); 1153} 1154 | 1087 /* If it's trunk, insert it in the head branch list. */ 1088 b = rcsrev_istrunk(d->revnum) ? rf->trunk : rcsfile_getbranch(rf, 1089 d->revnum); 1090 1091 /* 1092 * We didn't find a branch, check if we can find a branchpoint and 1093 * create a branch there. 1094 */ --- 71 unchanged lines hidden (view full) --- 1166 free(branchrev); 1167 return (b); 1168 } 1169 } 1170 free(branchrev); 1171 return (NULL); 1172} 1173 |
1155/* 1156 * Insert a delta into the correct place in the table of the rcsfile. Sorted by 1157 * date. 1158 */ | 1174/* Insert a delta into the correct place in the table of the rcsfile. */ |
1159static void 1160rcsfile_insertsorteddelta(struct rcsfile *rf, struct delta *d) 1161{ 1162 struct delta *d2; 1163 1164 /* If it's empty, insert into head. */ 1165 if (LIST_EMPTY(&rf->deltatable)) { 1166 LIST_INSERT_HEAD(&rf->deltatable, d, table_next); --- 168 unchanged lines hidden --- | 1175static void 1176rcsfile_insertsorteddelta(struct rcsfile *rf, struct delta *d) 1177{ 1178 struct delta *d2; 1179 1180 /* If it's empty, insert into head. */ 1181 if (LIST_EMPTY(&rf->deltatable)) { 1182 LIST_INSERT_HEAD(&rf->deltatable, d, table_next); --- 168 unchanged lines hidden --- |