git/builtin/grep.c

/*
 * Builtin "git grep"
 *
 * Copyright (c) 2006 Junio C Hamano
 */
#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "gettext.h"
#include "hex.h"
#include "config.h"
#include "tag.h"
#include "tree-walk.h"
#include "parse-options.h"
#include "string-list.h"
#include "run-command.h"
#include "grep.h"
#include "quote.h"
#include "dir.h"
#include "pathspec.h"
#include "setup.h"
#include "submodule.h"
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
#include "object-store-ll.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
#include "read-cache-ll.h"
#include "write-or-die.h"

static const char *grep_prefix;

static char const * const grep_usage[] =;

static int recurse_submodules;

static int num_threads;

static pthread_t *threads;

/* We use one producer thread and THREADS consumer
 * threads. The producer adds struct work_items to 'todo' and the
 * consumers pick work items from the same array.
 */
struct work_item {};

/* In the range [todo_done, todo_start) in 'todo' we have work_items
 * that have been or are processed by a consumer thread. We haven't
 * written the result for these to stdout yet.
 *
 * The work_items in [todo_start, todo_end) are waiting to be picked
 * up by a consumer thread.
 *
 * The ranges are modulo TODO_SIZE.
 */
#define TODO_SIZE
static struct work_item todo[TODO_SIZE];
static int todo_start;
static int todo_end;
static int todo_done;

/* Has all work items been added? */
static int all_work_added;

static struct repository **repos_to_free;
static size_t repos_to_free_nr, repos_to_free_alloc;

/* This lock protects all the variables above. */
static pthread_mutex_t grep_mutex;

static inline void grep_lock(void)
{}

static inline void grep_unlock(void)
{}

/* Signalled when a new work_item is added to todo. */
static pthread_cond_t cond_add;

/* Signalled when the result from one work_item is written to
 * stdout.
 */
static pthread_cond_t cond_write;

/* Signalled when we are finished with everything. */
static pthread_cond_t cond_result;

static int skip_first_line;

static void add_work(struct grep_opt *opt, struct grep_source *gs)
{}

static struct work_item *get_work(void)
{}

static void work_done(struct work_item *w)
{}

static void free_repos(void)
{}

static void *run(void *arg)
{}

static void strbuf_out(struct grep_opt *opt, const void *buf, size_t size)
{}

static void start_threads(struct grep_opt *opt)
{}

static int wait_all(void)
{}

static int grep_cmd_config(const char *var, const char *value,
			   const struct config_context *ctx, void *cb)
{}

static void grep_source_name(struct grep_opt *opt, const char *filename,
			     int tree_name_len, struct strbuf *out)
{}

static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
		     const char *filename, int tree_name_len,
		     const char *path)
{}

static int grep_file(struct grep_opt *opt, const char *filename)
{}

static void append_path(struct grep_opt *opt, const void *data, size_t len)
{}

static void run_pager(struct grep_opt *opt, const char *prefix)
{}

static int grep_cache(struct grep_opt *opt,
		      const struct pathspec *pathspec, int cached);
static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
		     struct tree_desc *tree, struct strbuf *base, int tn_len,
		     int check_attr);

static int grep_submodule(struct grep_opt *opt,
			  const struct pathspec *pathspec,
			  const struct object_id *oid,
			  const char *filename, const char *path, int cached)
{}

static int grep_cache(struct grep_opt *opt,
		      const struct pathspec *pathspec, int cached)
{}

static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
		     struct tree_desc *tree, struct strbuf *base, int tn_len,
		     int check_attr)
{}

static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
		       struct object *obj, const char *name, const char *path)
{}

static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
			const struct object_array *list)
{}

static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
			  int exc_std, int use_index)
{}

static int context_callback(const struct option *opt, const char *arg,
			    int unset)
{}

static int file_callback(const struct option *opt, const char *arg, int unset)
{}

static int not_callback(const struct option *opt, const char *arg, int unset)
{}

static int and_callback(const struct option *opt, const char *arg, int unset)
{}

static int open_callback(const struct option *opt, const char *arg, int unset)
{}

static int close_callback(const struct option *opt, const char *arg, int unset)
{}

static int pattern_callback(const struct option *opt, const char *arg,
			    int unset)
{}

int cmd_grep(int argc,
	     const char **argv,
	     const char *prefix,
	     struct repository *repo UNUSED)
{}