Esempio n. 1
0
File: git.c Progetto: benpeart/git
static void strip_extension(const char **argv)
{
	size_t len;

	if (strip_suffix(argv[0], STRIP_EXTENSION, &len))
		argv[0] = xmemdupz(argv[0], len);
}
Esempio n. 2
0
File: name-rev.c Progetto: 0369/git
static void name_rev(struct commit *commit,
		const char *tip_name, int generation, int distance,
		int deref)
{
	struct rev_name *name = (struct rev_name *)commit->util;
	struct commit_list *parents;
	int parent_number = 1;

	parse_commit(commit);

	if (commit->date < cutoff)
		return;

	if (deref) {
		tip_name = xstrfmt("%s^0", tip_name);

		if (generation)
			die("generation: %d, but deref?", generation);
	}

	if (name == NULL) {
		name = xmalloc(sizeof(rev_name));
		commit->util = name;
		goto copy_data;
	} else if (name->distance > distance) {
copy_data:
		name->tip_name = tip_name;
		name->generation = generation;
		name->distance = distance;
	} else
		return;

	for (parents = commit->parents;
			parents;
			parents = parents->next, parent_number++) {
		if (parent_number > 1) {
			size_t len;
			char *new_name;

			strip_suffix(tip_name, "^0", &len);
			if (generation > 0)
				new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
						   generation, parent_number);
			else
				new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
						   parent_number);

			name_rev(parents->item, new_name, 0,
				distance + MERGE_TRAVERSAL_WEIGHT, 0);
		} else {
			name_rev(parents->item, tip_name, generation + 1,
				distance + 1, 0);
		}
	}
}
Esempio n. 3
0
File: main.c Progetto: hharte/vttest
/*
 * Strip the string terminator (ST) from the given string, returning true if
 * we did this.
 */
int
strip_terminator(char *src)
{
  int ok = strip_suffix(src, st_input());
  if (!ok) {
    int have = (int) strlen(src);
    if (have > 0 && (unsigned char) src[have - 1] == ST) {
      ok = TRUE;
      src[--have] = '\0';
    }
  }
  if (!ok && LOG_ENABLED)
    fprintf(log_fp, "Missing ST\n");
  return ok;
}
Esempio n. 4
0
File: main.c Progetto: hharte/vttest
/* Parse the contents of a report from DECRQSS, returning the data as well */
int
parse_decrqss(char *report, const char *func)
{
  int code = -1;
  char *parse = report;

  if ((parse = skip_dcs(parse)) != 0
      && strip_terminator(parse)
      && strip_suffix(parse, func)) {
    if (!strncmp(parse, "1$r", (size_t) 3))
      code = 1;
    else if (!strncmp(parse, "0$r", (size_t) 3))
      code = 0;
  }

  if (code >= 0) {
    while ((*report++ = parse[3]) != '\0')
      parse++;
  }
  return code;
}
Esempio n. 5
0
File: help.c Progetto: CSRedRat/git
static void list_commands_in_dir(struct cmdnames *cmds,
					 const char *path,
					 const char *prefix)
{
	DIR *dir = opendir(path);
	struct dirent *de;
	struct strbuf buf = STRBUF_INIT;
	int len;

	if (!dir)
		return;
	if (!prefix)
		prefix = "git-";

	strbuf_addf(&buf, "%s/", path);
	len = buf.len;

	while ((de = readdir(dir)) != NULL) {
		const char *ent;
		size_t entlen;

		if (!skip_prefix(de->d_name, prefix, &ent))
			continue;

		strbuf_setlen(&buf, len);
		strbuf_addstr(&buf, de->d_name);
		if (!is_executable(buf.buf))
			continue;

		entlen = strlen(ent);
		strip_suffix(ent, ".exe", &entlen);

		add_cmdname(cmds, ent, entlen);
	}
	closedir(dir);
	strbuf_release(&buf);
}
Esempio n. 6
0
ToTeX::ToTeX(char* infilename)
{
    found_tab = 0;

    outbuf    = new char[BUFLEN];
    inbuf     = new char[BUFLEN];

    in_fname  = new char[strlen(infilename) + 10];
    strcpy(in_fname,infilename);
    strip_suffix(in_fname);

    out_fname = new char[strlen(in_fname) + 10];
    strcpy(out_fname,in_fname);
    strcat(out_fname,".tex");

    cout << " +++ Opening Output File: " << out_fname << NL;
    outfile.open(out_fname,ios::out);
    if (!outfile)
        error("Could not open output file.");

    // attempt to process the .h file

    int len = strlen(in_fname);
    in_fname[len  ] = '.';
    in_fname[len+1] = 'h';
    in_fname[len+2] = EOS;

    tex_mode = ON;
    process(in_fname);

    // attempt to process the .h file
    in_fname[len+1] = 'c';

    tex_mode = ON;
    process(in_fname);

}
Esempio n. 7
0
static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
{
	struct stat st;
	struct passwd *pwd;
	size_t pathlen;
	struct strbuf rel = STRBUF_INIT;
	char *p, *slash;
	int n;
	size_t size;

	if (stat(path->buf, &st)) {
		fprintf(stderr, "Error accessing %s: %s (%d)\n",
			path->buf, strerror(errno), errno);
		return;
	}

	strbuf_addch(path, '/');
	pathlen = path->len;

	if (ctx.cfg.strict_export) {
		strbuf_addstr(path, ctx.cfg.strict_export);
		if(stat(path->buf, &st))
			return;
		strbuf_setlen(path, pathlen);
	}

	strbuf_addstr(path, "noweb");
	if (!stat(path->buf, &st))
		return;
	strbuf_setlen(path, pathlen);

	if (!starts_with(path->buf, base))
		strbuf_addbuf(&rel, path);
	else
		strbuf_addstr(&rel, path->buf + strlen(base) + 1);

	if (!strcmp(rel.buf + rel.len - 5, "/.git"))
		strbuf_setlen(&rel, rel.len - 5);
	else if (rel.len && rel.buf[rel.len - 1] == '/')
		strbuf_setlen(&rel, rel.len - 1);

	repo = cgit_add_repo(rel.buf);
	config_fn = fn;
	if (ctx.cfg.enable_git_config) {
		strbuf_addstr(path, "config");
		git_config_from_file(gitconfig_config, path->buf, NULL);
		strbuf_setlen(path, pathlen);
	}

	if (ctx.cfg.remove_suffix) {
		size_t urllen;
		strip_suffix(repo->url, ".git", &urllen);
		strip_suffix_mem(repo->url, &urllen, "/");
		repo->url[urllen] = '\0';
	}
	repo->path = xstrdup(path->buf);
	while (!repo->owner) {
		if ((pwd = getpwuid(st.st_uid)) == NULL) {
			fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
				path->buf, strerror(errno), errno);
			break;
		}
		if (pwd->pw_gecos)
			if ((p = strchr(pwd->pw_gecos, ',')))
				*p = '\0';
		repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
	}

	if (repo->desc == cgit_default_repo_desc || !repo->desc) {
		strbuf_addstr(path, "description");
		if (!stat(path->buf, &st))
			readfile(path->buf, &repo->desc, &size);
		strbuf_setlen(path, pathlen);
	}

	if (ctx.cfg.section_from_path) {
		n = ctx.cfg.section_from_path;
		if (n > 0) {
			slash = rel.buf - 1;
			while (slash && n && (slash = strchr(slash + 1, '/')))
				n--;
		} else {
			slash = rel.buf + rel.len;
			while (slash && n && (slash = xstrrchr(rel.buf, slash - 1, '/')))
				n++;
		}
		if (slash && !n) {
			*slash = '\0';
			repo->section = xstrdup(rel.buf);
			*slash = '/';
			if (starts_with(repo->name, repo->section)) {
				repo->name += strlen(repo->section);
				if (*repo->name == '/')
					repo->name++;
			}
		}
	}

	strbuf_addstr(path, "cgitrc");
	if (!stat(path->buf, &st))
		parse_configfile(path->buf, &repo_config);

	strbuf_release(&rel);
}
Esempio n. 8
0
void XYUVHeader::Run(const ::options & options) {

    // If help has been requested, print it and quit.
    if (options.print_help) {
        PrintHelp();
        return;
    }

    // Otherwise do something useful.
#ifdef INSTALL_FORMATS_PATH
    // Load base formats from installation path
    config_manager_.load_configurations(INSTALL_FORMATS_PATH);
#endif

    // Load all additional formats supplied on the command line.
    for (const auto & path : options.additional_config_directories) {
        config_manager_.load_configurations(path);
    }

    // If a list of all formats has been requested, print it and quit.
    if (options.list_all_formats) {
        PrintAllFormats();
        return;
    }

    // Try to aquire each output stream.
    bool detect_concatinate = options.concatinate;
    std::vector<std::string> output_names;

    if (options.writeout) {
        // Make a set of output names to do argument validation.
        std::unordered_set<std::string> out_name_set;

        if ( options.output_name.size() == 0 ) {
            // If concatinating, use first file name as output.
            if (detect_concatinate) {
                std::string out_path = strip_suffix(options.input_files[0]) + ".xyuv";
                out_name_set.emplace(out_path);
                output_names.emplace_back(out_path);
            }
            else {
                for (const auto & in_file : options.input_files ) {
                    std::string out_path = strip_suffix(in_file) + ".xyuv";

                    out_name_set.insert(out_path);
                    output_names.emplace_back(out_path);
                }
            }
        }
        else {
            for (const auto & out_path : options.output_name ) {
                out_name_set.insert(out_path);
                output_names.emplace_back(out_path);
            }
        }

        // Check that no two output files overwrite one another.
        if (out_name_set.size() != output_names.size()) {
            throw std::invalid_argument("The same output name is given more than once. This is illegal for one invocation of the program.");
        }

        // Check that no input file is the same as an output file.
        // We don't account for relative paths etc here, but we won't care for now.
        for (const auto & in_path : options.input_files) {
            if (out_name_set.find(in_path) != out_name_set.end()) {
                throw std::invalid_argument("File '" + in_path + "' given as both an input and an output file, this is illegal.");
            }
        }

        // Check that the number of output files matches the number of input files
        // or one.
        if (output_names.size() != 1 && output_names.size() != options.input_files.size() ) {
            throw std::invalid_argument("If supplied, the number of output files must exactly match the number of input files or one.");
        }

        if (output_names.size() == 1 && options.input_files.size() > 1) {
            detect_concatinate = true;
        }
    }

    // Check validity of formats:
    std::vector<xyuv::format_template> format_templates;
    std::vector<xyuv::chroma_siting> sitings;
    std::vector<xyuv::conversion_matrix> matrices;

    for (const auto & format_template : options.output_formats ) {
        try {
            // Try to load the format-template from file.
            format_templates.push_back(xyuv::config_manager::load_format_template(format_template));
        } catch (std::runtime_error & e) {
            try {
                // If that failed look it up in the config manager.
                format_templates.push_back(config_manager_.get_format_template(format_template));
            } catch (std::exception e2) {
                std::string err_msg = std::string("Could not load format template ") + format_template +
                        ": " + e.what() + " and " + e2.what() + ". Please check the spelling of the argument.";
                throw std::invalid_argument(std::string(err_msg));
            }
        }
    }
    if (format_templates.size() != 1 && format_templates.size() != options.input_files.size()) {
        throw std::invalid_argument("The number of format templates must exactly match the number of input files or one (which implies all input files have the same format).");
    }

    for (const auto & siting : options.output_siting ) {
        try {
            // Try to load the siting from file.
            sitings.push_back(xyuv::config_manager::load_chroma_siting(siting));
        } catch (std::runtime_error & e) {
            try {
                // If that failed look it up in the config manager.
                sitings.push_back(config_manager_.get_chroma_siting(siting));
            } catch (std::exception e2) {
                std::string err_msg = std::string("Could not load chroma siting ") + siting +
                                      ": " + e.what() + " and " + e2.what() + ". Please check the spelling of the argument.";
                throw std::invalid_argument(std::string(err_msg));
            }
        }
    }
    if (sitings.size() != 1 && sitings.size() != options.input_files.size()) {
        throw std::invalid_argument("The number of chroma sitings must exactly match the number of input files or one (which implies all input files have the same chroma siting).");
    }

    for (const auto & matrix : options.output_matrix ) {
        try {
            // Try to load the matrix from file.
            matrices.push_back(xyuv::config_manager::load_conversion_matrix(matrix));
        } catch (std::runtime_error & e) {
            try {
                // If that failed look it up in the config manager.
                matrices.push_back(config_manager_.get_conversion_matrix(matrix));
            } catch (std::exception e2) {
                std::string err_msg = std::string("Could not load conversion matrix ") + matrix +
                                      ": " + e.what() + " and " + e2.what() + ". Please check the spelling of the argument.";
                throw std::invalid_argument(std::string(err_msg));
            }
        }
    }
    if (matrices.size() != 1 && matrices.size() != options.input_files.size()) {
        throw std::invalid_argument("The number of conversion matrices must exactly match the number of input files or one (which implies all input files have the same conversion matrix).");
    }

    // Do some extra checking for the chroma siting, which must match the subsampling mode of the format.
    if (sitings.size() == 1 && format_templates.size() > 1) {
        for (std::size_t i = 0; i < format_templates.size(); i++) {
            if (!(sitings[0].subsampling == format_templates[i].subsampling)) {
                throw std::invalid_argument("Sub-sampling mismatch, for format template #"
                                            + std::to_string(i) + "'" + options.output_formats[i] + "'"
                                            + " corresponding chroma siting expects subsampling mode: "
                                            + std::to_string(sitings[0].subsampling.macro_px_w) + "x" + std::to_string(sitings[0].subsampling.macro_px_h)
                                            + " got: "
                                            + std::to_string(format_templates[i].subsampling.macro_px_w) + "x" + std::to_string(format_templates[i].subsampling.macro_px_h)
                );
            }
        }
    }

    if (options.display && options.input_files.size() != 1 ) {
        throw std::invalid_argument("--display only supported for a single input.");
    }

    if (options.input_files.size() == 0) {
        throw std::logic_error("Missing input files.");
    }

    if (options.input_files.size() > 0 && options.image_w * options.image_h == 0) {
        throw std::logic_error("Image size must be non-zero.");
    }

    std::unique_ptr<std::ofstream> fout;
    if (detect_concatinate) {
        fout.reset(new std::ofstream(output_names[0], std::ios::binary | std::ios::app ));
        if (!(*fout)) {
            throw std::runtime_error("Could not open output file: '" + output_names[0] + "' for writing");
        }
    }

    // At this point everything looks good :) Lets load some formats.
    for ( std::size_t i = 0; i < options.input_files.size(); i++) {
        xyuv::format target_format = xyuv::create_format(
                options.image_w,
                options.image_h,
                format_templates.size() == 1 ? format_templates[0] : format_templates[i],
                matrices.size() == 1 ? matrices[0] : matrices[i],
                sitings.size() == 1 ? sitings[0] : sitings[i]
        );

        xyuv::frame frame = LoadConvertFrame(target_format, options.input_files[i]);

        // If --flip-y is set then change the image origin to the inverse.
        if (options.flip_y) {
            switch (frame.format.origin) {
                case xyuv::image_origin::UPPER_LEFT:
                    frame.format.origin = xyuv::image_origin::LOWER_LEFT;
                    break;
                case xyuv::image_origin::LOWER_LEFT:
                    frame.format.origin = xyuv::image_origin::UPPER_LEFT;
                    break;
                default:
                    break;
            }
        }

        if (options.writeout) {
            if (options.concatinate) {
                // Append file at end of concatinated string.
                xyuv::write_frame(*fout, frame);
            }
            else {
                try {
                    WriteFrame(frame, output_names[i]);
                } catch (std::exception & e) {
                    std::cout << "[Warning] Error occured while writing file '" <<
                                 output_names[i] << "'\n   " <<
                                 e.what() << "\n   Skipping file." << std::endl;
                }
            }
        }

        if (options.display) {
            Display(frame);
        }
    }
}
Esempio n. 9
0
File: connected.c Progetto: 9b/git
/*
 * If we feed all the commits we want to verify to this command
 *
 *  $ git rev-list --objects --stdin --not --all
 *
 * and if it does not error out, that means everything reachable from
 * these commits locally exists and is connected to our existing refs.
 * Note that this does _not_ validate the individual objects.
 *
 * Returns 0 if everything is connected, non-zero otherwise.
 */
int check_connected(sha1_iterate_fn fn, void *cb_data,
		    struct check_connected_options *opt)
{
	struct child_process rev_list = CHILD_PROCESS_INIT;
	struct check_connected_options defaults = CHECK_CONNECTED_INIT;
	char commit[41];
	unsigned char sha1[20];
	int err = 0;
	struct packed_git *new_pack = NULL;
	struct transport *transport;
	size_t base_len;

	if (!opt)
		opt = &defaults;
	transport = opt->transport;

	if (fn(cb_data, sha1)) {
		if (opt->err_fd)
			close(opt->err_fd);
		return err;
	}

	if (transport && transport->smart_options &&
	    transport->smart_options->self_contained_and_connected &&
	    transport->pack_lockfile &&
	    strip_suffix(transport->pack_lockfile, ".keep", &base_len)) {
		struct strbuf idx_file = STRBUF_INIT;
		strbuf_add(&idx_file, transport->pack_lockfile, base_len);
		strbuf_addstr(&idx_file, ".idx");
		new_pack = add_packed_git(idx_file.buf, idx_file.len, 1);
		strbuf_release(&idx_file);
	}

	if (opt->shallow_file) {
		argv_array_push(&rev_list.args, "--shallow-file");
		argv_array_push(&rev_list.args, opt->shallow_file);
	}
	argv_array_push(&rev_list.args,"rev-list");
	argv_array_push(&rev_list.args, "--objects");
	argv_array_push(&rev_list.args, "--stdin");
	argv_array_push(&rev_list.args, "--not");
	argv_array_push(&rev_list.args, "--all");
	argv_array_push(&rev_list.args, "--quiet");
	if (opt->progress)
		argv_array_pushf(&rev_list.args, "--progress=%s",
				 _("Checking connectivity"));

	rev_list.git_cmd = 1;
	rev_list.env = opt->env;
	rev_list.in = -1;
	rev_list.no_stdout = 1;
	if (opt->err_fd)
		rev_list.err = opt->err_fd;
	else
		rev_list.no_stderr = opt->quiet;

	if (start_command(&rev_list))
		return error(_("Could not run 'git rev-list'"));

	sigchain_push(SIGPIPE, SIG_IGN);

	commit[40] = '\n';
	do {
		/*
		 * If index-pack already checked that:
		 * - there are no dangling pointers in the new pack
		 * - the pack is self contained
		 * Then if the updated ref is in the new pack, then we
		 * are sure the ref is good and not sending it to
		 * rev-list for verification.
		 */
		if (new_pack && find_pack_entry_one(sha1, new_pack))
			continue;

		memcpy(commit, sha1_to_hex(sha1), 40);
		if (write_in_full(rev_list.in, commit, 41) < 0) {
			if (errno != EPIPE && errno != EINVAL)
				error_errno(_("failed write to rev-list"));
			err = -1;
			break;
		}
	} while (!fn(cb_data, sha1));

	if (close(rev_list.in))
		err = error_errno(_("failed to close rev-list's stdin"));

	sigchain_pop(SIGPIPE);
	return finish_command(&rev_list) || err;
}