Exemplo n.º 1
0
static struct revision *lookup_rev(unsigned char *sha1)
{
	int pos = find_rev(sha1);
	struct revision *n;

	if (pos >= 0)
		return revs[pos];
	
	pos = -pos-1;

	if (rev_allocs == nr_revs) {
		rev_allocs = alloc_nr(rev_allocs);
		revs = realloc(revs, rev_allocs * sizeof(struct revision *));
	}
	n = malloc(sizeof(struct revision));

	n->flags = 0;
	memcpy(n->sha1, sha1, 20);
	n->parent = NULL;

	/* Insert it into the right place */
	memmove(revs + pos + 1, revs + pos, (nr_revs - pos) * sizeof(struct revision *));
	revs[pos] = n;
	nr_revs++;

	return n;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    for(int i = 1; i < argc; i++)
    {
        if(argv[i] == NULL) continue;
        if(strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--replace", 9) == 0)
            allow_replace = true;
        else if(strncmp(argv[i], "-l", 2) == 0 || strncmp(argv[i], "--local", 7) == 0)
            local = true;
        else if(strncmp(argv[i], "-f", 2) == 0 || strncmp(argv[i], "--fetch", 7) == 0)
            do_fetch = true;
        else if(strncmp(argv[i], "-s", 2) == 0 || strncmp(argv[i], "--sql", 5) == 0)
            do_sql = true;
        else if(strncmp(argv[i], "--branch=", 9) == 0)
            snprintf(remote_branch, MAX_REMOTE, "%s", argv[i] + 9);
        else if(strncmp(argv[i], "-h", 2) == 0 || strncmp(argv[i], "--help", 6) == 0)
        {
            printf("Usage: git_id [OPTION]\n");
            printf("Generates a new rev number and updates revision_nr.h and the commit message.\n");
            printf("Should be used just before push.\n");
            printf("   -h, --help            show the usage\n");
            printf("   -r, --replace         replace the rev number if it was already applied\n");
            printf("                         to the last commit\n");
            printf("   -l, --local           search for the highest rev number on HEAD\n");
            printf("   -f, --fetch           fetch from origin before searching for the new rev\n");
            printf("   -s, --sql             search for new sql updates and do all of the changes\n");
            printf("                         for the new rev\n");
            printf("       --branch=BRANCH   specify which remote branch to use\n");
            return 0;
        }
    }

    DO( find_path()                     );
    if(!local)
    {
        DO( find_origin()               );
        if(do_fetch)
            DO( fetch_origin()          );
        DO( check_fwd()                 );
    }
    DO( find_rev()                      );
    DO( find_head_msg()                 );
    if(do_sql)
        DO( find_sql_updates()          );
    DO( prepare_new_index()             );
    DO( write_rev_nr()                  );
    if(do_sql)
    {
        DO( convert_sql_updates()       );
        DO( generate_sql_makefile()     );
        //DO( change_sql_database()       );
        DO( write_rev_sql()             );
    }
    DO( amend_commit()                  );
    DO( cleanup_new_index()             );
    //if(do_sql)
    //    DO( change_sql_history()        );

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    for(int i = 1; i < argc; i++)
    {
        if(argv[i] == NULL) continue;
        if(strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--replace", 2) == 0)
            allow_replace = true;
        if(strncmp(argv[i], "-l", 2) == 0 || strncmp(argv[i], "--local", 2) == 0)
            local = true;
        if(strncmp(argv[i], "-f", 2) == 0 || strncmp(argv[i], "--fetch", 2) == 0)
            do_fetch = true;
        if(strncmp(argv[i], "-h", 2) == 0 || strncmp(argv[i], "--help", 2) == 0)
        {
            printf("Usage: git_id [OPTION]\n");
            printf("Generates a new rev number and updates revision_nr.h and the commit message.\n");
            printf("Should be used just before push.\n");
            printf("   -h, --help     show the usage\n");
            printf("   -r, --replace  replace the rev number if it was already applied to the last\n");
            printf("                  commit\n");
            printf("   -l, --local    search for the highest rev number on HEAD\n");
            printf("   -f, --fetch    fetch from origin before searching for the new rev\n");
            return 0;
        }
    }

    DO( find_path()     );
    if(!local)
    {
        DO( find_origin()   );
        if(do_fetch)
        {
            DO( fetch_origin()  );
            DO( check_fwd()     );
        }
    }
    DO( find_rev()      );
    DO( find_head_msg() );
    DO( write_rev()     );
    DO( amend_commit()  );

    return 0;
}