Fossil SCM

Enhance the graph generator so that it uses less memory and so that it is not limited to a fixed number of parents (10) for each node.

drh 2011-02-07 14:34 trunk
Commit 5ee80c545dbb6b06032d946c33b3e28e9044cbe8
1 file changed +6 -4
+6 -4
--- src/graph.c
+++ src/graph.c
@@ -21,11 +21,10 @@
2121
#include "graph.h"
2222
#include <assert.h>
2323
2424
#if INTERFACE
2525
26
-#define GR_MAX_PARENT 10 /* Max number of parents for any one node */
2726
#define GR_MAX_RAIL 32 /* Max number of "rails" to display */
2827
2928
/* The graph appears vertically beside a timeline. Each row in the
3029
** timeline corresponds to a row in the graph. GraphRow.idx is 0 for
3130
** the top-most row and increases moving down. Hence (in the absence of
@@ -32,11 +31,11 @@
3231
** time skew) parents have a larger index than their children.
3332
*/
3433
struct GraphRow {
3534
int rid; /* The rid for the check-in */
3635
i8 nParent; /* Number of parents */
37
- int aParent[GR_MAX_PARENT]; /* Array of parents. 0 element is primary .*/
36
+ int *aParent; /* Array of parents. 0 element is primary .*/
3837
char *zBranch; /* Branch name */
3938
char *zBgClr; /* Background Color */
4039
4140
GraphRow *pNext; /* Next row down in the list of all rows */
4241
GraphRow *pPrev; /* Previous row */
@@ -167,14 +166,17 @@
167166
int *aParent, /* Array of parents */
168167
const char *zBranch, /* Branch for this check-in */
169168
const char *zBgClr /* Background color. NULL or "" for white. */
170169
){
171170
GraphRow *pRow;
171
+ int nByte;
172172
173173
if( p->nErr ) return 0;
174
- if( nParent>GR_MAX_PARENT ){ p->nErr++; return 0; }
175
- pRow = (GraphRow*)safeMalloc( sizeof(GraphRow) );
174
+ nByte = sizeof(GraphRow);
175
+ nByte += sizeof(pRow->aParent[0])*nParent;
176
+ pRow = (GraphRow*)safeMalloc( nByte );
177
+ pRow->aParent = (int*)&pRow[1];
176178
pRow->rid = rid;
177179
pRow->nParent = nParent;
178180
pRow->zBranch = persistBranchName(p, zBranch);
179181
if( zBgClr==0 || zBgClr[0]==0 ) zBgClr = "white";
180182
pRow->zBgClr = persistBranchName(p, zBgClr);
181183
--- src/graph.c
+++ src/graph.c
@@ -21,11 +21,10 @@
21 #include "graph.h"
22 #include <assert.h>
23
24 #if INTERFACE
25
26 #define GR_MAX_PARENT 10 /* Max number of parents for any one node */
27 #define GR_MAX_RAIL 32 /* Max number of "rails" to display */
28
29 /* The graph appears vertically beside a timeline. Each row in the
30 ** timeline corresponds to a row in the graph. GraphRow.idx is 0 for
31 ** the top-most row and increases moving down. Hence (in the absence of
@@ -32,11 +31,11 @@
32 ** time skew) parents have a larger index than their children.
33 */
34 struct GraphRow {
35 int rid; /* The rid for the check-in */
36 i8 nParent; /* Number of parents */
37 int aParent[GR_MAX_PARENT]; /* Array of parents. 0 element is primary .*/
38 char *zBranch; /* Branch name */
39 char *zBgClr; /* Background Color */
40
41 GraphRow *pNext; /* Next row down in the list of all rows */
42 GraphRow *pPrev; /* Previous row */
@@ -167,14 +166,17 @@
167 int *aParent, /* Array of parents */
168 const char *zBranch, /* Branch for this check-in */
169 const char *zBgClr /* Background color. NULL or "" for white. */
170 ){
171 GraphRow *pRow;
 
172
173 if( p->nErr ) return 0;
174 if( nParent>GR_MAX_PARENT ){ p->nErr++; return 0; }
175 pRow = (GraphRow*)safeMalloc( sizeof(GraphRow) );
 
 
176 pRow->rid = rid;
177 pRow->nParent = nParent;
178 pRow->zBranch = persistBranchName(p, zBranch);
179 if( zBgClr==0 || zBgClr[0]==0 ) zBgClr = "white";
180 pRow->zBgClr = persistBranchName(p, zBgClr);
181
--- src/graph.c
+++ src/graph.c
@@ -21,11 +21,10 @@
21 #include "graph.h"
22 #include <assert.h>
23
24 #if INTERFACE
25
 
26 #define GR_MAX_RAIL 32 /* Max number of "rails" to display */
27
28 /* The graph appears vertically beside a timeline. Each row in the
29 ** timeline corresponds to a row in the graph. GraphRow.idx is 0 for
30 ** the top-most row and increases moving down. Hence (in the absence of
@@ -32,11 +31,11 @@
31 ** time skew) parents have a larger index than their children.
32 */
33 struct GraphRow {
34 int rid; /* The rid for the check-in */
35 i8 nParent; /* Number of parents */
36 int *aParent; /* Array of parents. 0 element is primary .*/
37 char *zBranch; /* Branch name */
38 char *zBgClr; /* Background Color */
39
40 GraphRow *pNext; /* Next row down in the list of all rows */
41 GraphRow *pPrev; /* Previous row */
@@ -167,14 +166,17 @@
166 int *aParent, /* Array of parents */
167 const char *zBranch, /* Branch for this check-in */
168 const char *zBgClr /* Background color. NULL or "" for white. */
169 ){
170 GraphRow *pRow;
171 int nByte;
172
173 if( p->nErr ) return 0;
174 nByte = sizeof(GraphRow);
175 nByte += sizeof(pRow->aParent[0])*nParent;
176 pRow = (GraphRow*)safeMalloc( nByte );
177 pRow->aParent = (int*)&pRow[1];
178 pRow->rid = rid;
179 pRow->nParent = nParent;
180 pRow->zBranch = persistBranchName(p, zBranch);
181 if( zBgClr==0 || zBgClr[0]==0 ) zBgClr = "white";
182 pRow->zBgClr = persistBranchName(p, zBgClr);
183

Keyboard Shortcuts

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