Ejemplo n.º 1
0
static void stat_ps_tree_node(const void * nodep, const VISIT which, const int depth)
{
    int desc_len;
    PatchSet * ps;
    struct list_head * next;
    int counter;
    void * old;

    /* Make sure we have it if we do statistics */
    if (!author_hash)
	author_hash = create_hash_table(1023);

    switch(which)
    {
    case postorder:
    case leaf:
	ps = *(PatchSet**)nodep;
	num_patch_sets++;

	old = NULL;

	/* Author statistics */
	if (put_hash_object_ex(author_hash, ps->author, ps->author, HT_NO_KEYCOPY, NULL, &old) >= 0 && !old)
	{
	    int len = strlen(ps->author);
	    num_authors++;
	    max_author_len = MAX(max_author_len, len);
	    total_author_len += len;
	}

	/* Log message statistics */
	desc_len = strlen(ps->descr);
	max_descr_len = MAX(max_descr_len, desc_len);
	total_descr_len += desc_len;
	
	/* PatchSet member statistics */
	counter = 0;
	next = ps->members.next;
	while (next != &ps->members)
	{
	    counter++;
	    next = next->next;
	}

	num_ps_member += counter;
	max_ps_member_in_ps = MAX(max_ps_member_in_ps, counter);
	break;

    default:
	break;
    }
}
Ejemplo n.º 2
0
/* FIXME: there is no way for the user of this to determine the difference
 *        between a put to a new key value and a malloc failure
 */
void *put_hash_object(struct hash_table *tbl, const char *key, void *obj)
{
    void * retval;
    put_hash_object_ex(tbl, key, obj, HT_KEYCOPY, NULL, &retval);
    return retval;
}
Ejemplo n.º 3
0
time_t read_cache()
{
    FILE * fp;
    char buff[BUFSIZ];
    int state = CACHE_NEED_FILE;
    CvsFile * f = NULL;
    PatchSet * ps = NULL;
    char datebuff[20] = "";
    char authbuff[AUTH_STR_MAX] = "";
    char tagbuff[LOG_STR_MAX] = "";
    int tag_flags = 0;
    char branchbuff[LOG_STR_MAX] = "";
    int branch_add = 0;
    int logbufflen = LOG_STR_MAX + 1;
    char * logbuff = malloc(logbufflen);
    time_t cache_date = -1;
    int read_version;

    if (logbuff == NULL)
    {
	debug(DEBUG_SYSERROR, "could not malloc %d bytes for logbuff in read_cache", logbufflen);
	exit(1);
    }

    logbuff[0] = 0;

    if (!(fp = cache_open("r")))
	goto out;

    /* first line is cache version  format "cache version: %d\n" */
    if (!fgets(buff, BUFSIZ, fp) || strncmp(buff, "cache version:", 14))
    {
	debug(DEBUG_APPERROR, "bad cvsps.cache file");
	goto out_close;
    }

    if ((read_version = atoi(buff + 15)) != cache_version)
    {
	debug(DEBUG_APPERROR, "bad cvsps.cache version %d, expecting %d.  ignoring cache",
	      read_version, cache_version);
	goto out_close;
    }

    /* second line is date cache was created, format "cache date: %d\n" */
    if (!fgets(buff, BUFSIZ, fp) || strncmp(buff, "cache date:", 11))
    {
	debug(DEBUG_APPERROR, "bad cvsps.cache file");
	goto out_close;
    }

    cache_date = atoi(buff + 12);
    debug(DEBUG_STATUS, "read cache_date %d", (int)cache_date);

    while (fgets(buff, BUFSIZ, fp))
    {
	int len = strlen(buff);

	switch(state)
	{
	case CACHE_NEED_FILE:
	    if (strncmp(buff, "file:", 5) == 0)
	    {
		len -= 6;
		f = create_cvsfile();
		f->filename = xstrdup(buff + 6);
		f->filename[len-1] = 0; /* Remove the \n at the end of line */
		debug(DEBUG_STATUS, "read cache filename '%s'", f->filename);
		put_hash_object_ex(file_hash, f->filename, f, HT_NO_KEYCOPY, NULL, NULL);
		state = CACHE_NEED_BRANCHES;
	    }
	    else
	    {
		state = CACHE_NEED_PS;
	    }
	    break;
	case CACHE_NEED_BRANCHES:
	    if (buff[0] != '\n')
	    {
		char * tag;

		tag = strchr(buff, ':');
		if (tag)
		{
		    *tag = 0;
		    tag += 2;
		    buff[len - 1] = 0;
		    cvs_file_add_branch(f, buff, tag);
		}
	    }
	    else
	    {
		f->have_branches = 1;
		state = CACHE_NEED_SYMBOLS;
	    }
	    break;
	case CACHE_NEED_SYMBOLS:
	    if (buff[0] != '\n')
	    {
		char * rev;

		rev = strchr(buff, ':');
		if (rev)
		{
		    *rev = 0;
		    rev += 2;
		    buff[len - 1] = 0;
		    cvs_file_add_symbol(f, rev, buff);
		}
	    }
	    else
	    {
		state = CACHE_NEED_REV;
	    }
	    break;
	case CACHE_NEED_REV:
	    if (isdigit(buff[0]))
	    {
		char * p = strchr(buff, ' ');
		if (p)
		{
		    CvsFileRevision * rev;
		    *p++ = 0;
		    buff[len-1] = 0;
		    rev = cvs_file_add_revision(f, buff);
		    if (strcmp(rev->branch, p) != 0)
		    {
			debug(DEBUG_APPERROR, "branch mismatch for %s:%s %s != %s", 
			      rev->file->filename, rev->rev, rev->branch, p);
		    }
		}
	    }
	    else
	    {
		state = CACHE_NEED_FILE;
	    }
	    break;
	case CACHE_NEED_PS:
	    if (strncmp(buff, "patchset:", 9) == 0)
		state = CACHE_NEED_PS_DATE;
	    break;
	case CACHE_NEED_PS_DATE:
	    if (strncmp(buff, "date:", 5) == 0)
	    {
		/* remove prefix "date: " and LF from len */
		len -= 6;
		strzncpy(datebuff, buff + 6, MIN(len, sizeof(datebuff)));
		state = CACHE_NEED_PS_AUTHOR;
	    }
	    break;
	case CACHE_NEED_PS_AUTHOR:
	    if (strncmp(buff, "author:", 7) == 0)
	    {
		/* remove prefix "author: " and LF from len */
		len -= 8;
		strzncpy(authbuff, buff + 8, MIN(len, AUTH_STR_MAX));
		state = CACHE_NEED_PS_TAG;
	    }
	    break;
	case CACHE_NEED_PS_TAG:
	    if (strncmp(buff, "tag:", 4) == 0)
	    {
		/* remove prefix "tag: " and LF from len */
		len -= 5;
		strzncpy(tagbuff, buff + 5, MIN(len, LOG_STR_MAX));
		state = CACHE_NEED_PS_TAG_FLAGS;
	    }
	    break;
	case CACHE_NEED_PS_TAG_FLAGS:
	    if (strncmp(buff, "tag_flags:", 10) == 0)
	    {
		/* remove prefix "tag_flags: " and LF from len */
		len -= 11;
		tag_flags = atoi(buff + 11);
		state = CACHE_NEED_PS_BRANCH;
	    }
	    break;
	case CACHE_NEED_PS_BRANCH:
	    if (strncmp(buff, "branch:", 7) == 0)
	    {
		/* remove prefix "branch: " and LF from len */
		len -= 8;
		strzncpy(branchbuff, buff + 8, MIN(len, LOG_STR_MAX));
		state = CACHE_NEED_PS_BRANCH_ADD;
	    }
	    break;
	case CACHE_NEED_PS_BRANCH_ADD:
	    if (strncmp(buff, "branch_add:", 11) == 0)
	    {
		/* remove prefix "branch_add: " and LF from len */
		len -= 12;
		branch_add = atoi(buff + 12);
		state = CACHE_NEED_PS_DESCR;
	    }
	    break;
	case CACHE_NEED_PS_DESCR:
	    if (strncmp(buff, "descr:", 6) == 0)
		state = CACHE_NEED_PS_EOD;
	    break;
	case CACHE_NEED_PS_EOD:
	    if (strcmp(buff, CACHE_DESCR_BOUNDARY) == 0)
	    {
		debug(DEBUG_STATUS, "patch set %s %s %s %s", datebuff, authbuff, logbuff, branchbuff);
		ps = get_patch_set(datebuff, logbuff, authbuff, branchbuff, NULL);
		/* the tag and tag_flags will be assigned by the resolve_global_symbols code 
		 * ps->tag = (strlen(tagbuff)) ? get_string(tagbuff) : NULL;
		 * ps->tag_flags = tag_flags;
		 */
		ps->branch_add = branch_add;
		state = CACHE_NEED_PS_MEMBERS;
	    }
	    else
	    {
		/* Make sure we have enough in the buffer */
		int len = strlen(buff);
		if (strlen(logbuff) + len >= LOG_STR_MAX)
		{
		    logbufflen += (len >= LOG_STR_MAX ? (len+1) : LOG_STR_MAX);
		    char * newlogbuff = realloc(logbuff, logbufflen);
		    if (newlogbuff == NULL)
		    {
			debug(DEBUG_SYSERROR, "could not realloc %d bytes for logbuff in read_cache", logbufflen);
			exit(1);
		    }
		    logbuff = newlogbuff;
		}
		strcat(logbuff, buff);
	    }
	    break;
	case CACHE_NEED_PS_MEMBERS:
	    if (strncmp(buff, "members:", 8) == 0)
		state = CACHE_NEED_PS_EOM;
	    break;
	case CACHE_NEED_PS_EOM:
	    if (buff[0] == '\n')
	    {
		datebuff[0] = 0;
		authbuff[0] = 0;
		tagbuff[0] = 0;
		tag_flags = 0;
		branchbuff[0] = 0;
		branch_add = 0;
		logbuff[0] = 0;
		state = CACHE_NEED_PS;
	    }
	    else
	    {
		PatchSetMember * psm = create_patch_set_member();
		parse_cache_revision(psm, buff);
		patch_set_add_member(ps, psm);
	    }
	    break;
	}
    }

 out_close:
    fclose(fp);
 out:
    free(logbuff);

    return cache_date;
}