Exemple #1
0
std::string project_info::get_branch_string()
{
	std::string r;
	uint64_t j = active_branch;
	if(!j)
		return "(root)";
	while(j) {
		if(r == "")
			r = get_branch_name(j);
		else
			r = get_branch_name(j) + "→" + r;
		j = get_parent_branch(j);
	}
	return r;
}
Exemple #2
0
static int
svn_read_custom(FILE *fp, char line[], int size, int line_num, result_t *result)
{
    // Caller has already read line 1. Read lines 2..5, discarding 2..4.
    while (line_num <= 5) {
        if (fgets(line, size, fp) == NULL) {
            debug(".svn/entries: early EOF (line %d empty)", line_num);
            return 0;
        }
        line_num++;
    }

    // Line 5 is the complete URL for the working dir (repos_root
    // + repos_path). To parse it easily, we first need the
    // repos_root from line 6.
    char *repos_root;
    int root_len;
    char *repos_path = strdup(line);
    chop_newline(repos_path);
    if (fgets(line, size, fp) == NULL) {
        debug(".svn/entries: early EOF (line %d empty)", line_num);
        return 0;
    }
    line_num++;
    repos_root = line;
    chop_newline(repos_root);
    root_len = strlen(repos_root);
    if (strncmp(repos_path, repos_root, root_len) != 0) {
        debug(".svn/entries: repos_path (%s) does not start with "
              "repos_root (%s)",
              repos_path, repos_root);
        free(repos_path);
        return 0;
    }

    // Lines 6 .. 10 are also uninteresting.
    while (line_num <= 11) {
        if (fgets(line, size, fp) == NULL) {
            debug(".svn/entries: early EOF (line %d empty)", line_num);
            return 0;
        }
        line_num++;
    }

    // Line 11 is the revision number we care about, now in 'line'.
    chop_newline(line);
    result->revision = strdup(line);
    debug("read svn revision from .svn/entries: '%s'", line);

    result->branch = get_branch_name(repos_path + root_len + 1, result->revision);
    free(repos_path);

    return 1;
}
Exemple #3
0
void project_state::recursive_list_branch(uint64_t bid, std::set<unsigned>& dset, unsigned depth, bool last_of)
{
	auto prj = get();
	if(!prj) {
		messages << "Not in project context." << std::endl;
		return;
	}
	std::set<uint64_t> children = prj->branch_children(bid);
	std::string prefix;
	for(unsigned i = 0; i + 1 < depth; i++)
		prefix += (dset.count(i) ? "\u2502" : " ");
	prefix += (dset.count(depth - 1) ? (last_of ? "\u2514" : "\u251c") : " ");
	if(last_of) dset.erase(depth - 1);
	messages << prefix
		<< ((bid == prj->get_current_branch()) ? "*" : "")
		<< bid << ":" << prj->get_branch_name(bid) << std::endl;
	dset.insert(depth);
	size_t c = 0;
	for(auto i : children) {
		bool last = (++c == children.size());
		recursive_list_branch(i, dset, depth + 1, last);
	}
	dset.erase(depth);
}
Exemple #4
0
static int
svn_read_sqlite(vccontext_t *context, result_t *result)
{
    int ok = 0;
    int retval;
    sqlite3 *conn = NULL;
    sqlite3_stmt *res = NULL;
    const char *tail;
    char * repos_path = NULL;

    retval = sqlite3_open_v2(".svn/wc.db", &conn, SQLITE_OPEN_READONLY, NULL);
    if (retval != SQLITE_OK) {
        debug("error opening database in .svn/wc.db: %s", sqlite3_errmsg(conn));
        goto err;
    }
    // unclear when wc_id is anything other than 1
    char *sql = ("select changed_revision from nodes "
                 "where wc_id = 1 and local_relpath = ''");
    const char *textval;
    retval = sqlite3_prepare_v2(conn, sql, strlen(sql), &res, &tail);
    if (retval != SQLITE_OK) {
        debug("error running query: %s", sqlite3_errmsg(conn));
        goto err;
    }
    retval = sqlite3_step(res);
    if (retval != SQLITE_DONE && retval != SQLITE_ROW) {
        debug("error fetching result row: %s", sqlite3_errmsg(conn));
        goto err;
    }
    textval = (const char *) sqlite3_column_text(res, 0);
    if (textval == NULL) {
        debug("could not retrieve value of nodes.changed_revision");
        goto err;
    }
    result->revision = strdup(textval);
    sqlite3_finalize(res);

    sql = "select repos_path from nodes where local_relpath = ?";
    retval = sqlite3_prepare_v2(conn, sql, strlen(sql), &res, &tail);
    if (retval != SQLITE_OK) {
        debug("error querying for repos_path: %s", sqlite3_errmsg(conn));
        goto err;
    }
    retval = sqlite3_bind_text(res, 1,
                               context->rel_path, strlen(context->rel_path),
                               SQLITE_STATIC);
    if (retval != SQLITE_OK) {
        debug("error binding parameter: %s", sqlite3_errmsg(conn));
        goto err;
    }
    retval = sqlite3_step(res);
    if (retval != SQLITE_DONE && retval != SQLITE_ROW) {
        debug("error fetching result row: %s", sqlite3_errmsg(conn));
        goto err;
    }

    textval = (const char *) sqlite3_column_text(res, 0);
    if (textval == NULL) {
        debug("could not retrieve value of nodes.repos_path");
        goto err;
    }
    repos_path = strdup(textval);
    result->branch = get_branch_name(repos_path, result->revision);

    ok = 1;

 err:
    if (res != NULL)
        sqlite3_finalize(res);
    if (conn != NULL)
        sqlite3_close(conn);
    if (repos_path != NULL)
        free(repos_path);
    return ok;
}