Re: [PATCH 1/5] Move reset_index_file() to a new reset.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 24 May 2008, Miklos Vajna wrote:

> This is needed as we want to use it later in builtin-merge.
> 
> Signed-off-by: Miklos Vajna <vmiklos@xxxxxxxxxxxxxx>
> ---
>  Makefile        |    2 ++
>  builtin-reset.c |   17 +----------------
>  reset.c         |   28 ++++++++++++++++++++++++++++
>  reset.h         |    6 ++++++
>  4 files changed, 37 insertions(+), 16 deletions(-)
>  create mode 100644 reset.c
>  create mode 100644 reset.h
> 
> diff --git a/Makefile b/Makefile
> index a2de075..91d938a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -364,6 +364,7 @@ LIB_H += quote.h
>  LIB_H += reflog-walk.h
>  LIB_H += refs.h
>  LIB_H += remote.h
> +LIB_H += reset.h
>  LIB_H += revision.h
>  LIB_H += run-command.h
>  LIB_H += sha1-lookup.h
> @@ -443,6 +444,7 @@ LIB_OBJS += read-cache.o
>  LIB_OBJS += reflog-walk.o
>  LIB_OBJS += refs.o
>  LIB_OBJS += remote.o
> +LIB_OBJS += reset.o
>  LIB_OBJS += revision.o
>  LIB_OBJS += run-command.o
>  LIB_OBJS += server-info.o
> diff --git a/builtin-reset.c b/builtin-reset.c
> index 79424bb..6e6e168 100644
> --- a/builtin-reset.c
> +++ b/builtin-reset.c
> @@ -18,6 +18,7 @@
>  #include "tree.h"
>  #include "branch.h"
>  #include "parse-options.h"
> +#include "reset.h"
>  
>  static const char * const git_reset_usage[] = {
>  	"git-reset [--mixed | --soft | --hard] [-q] [<commit>]",
> @@ -49,22 +50,6 @@ static inline int is_merge(void)
>  	return !access(git_path("MERGE_HEAD"), F_OK);
>  }
>  
> -static int reset_index_file(const unsigned char *sha1, int is_hard_reset)
> -{
> -	int i = 0;
> -	const char *args[6];
> -
> -	args[i++] = "read-tree";
> -	args[i++] = "-v";
> -	args[i++] = "--reset";
> -	if (is_hard_reset)
> -		args[i++] = "-u";
> -	args[i++] = sha1_to_hex(sha1);
> -	args[i] = NULL;
> -
> -	return run_command_v_opt(args, RUN_GIT_CMD);
> -}
> -
>  static void print_new_head_line(struct commit *commit)
>  {
>  	const char *hex, *body;
> diff --git a/reset.c b/reset.c
> new file mode 100644
> index 0000000..a75fec6
> --- /dev/null
> +++ b/reset.c
> @@ -0,0 +1,28 @@
> +/*
> + * generic fucntion(s) from the "git reset" builtin command
> + *
> + * Copyright (c) 2007 Carlos Rica
> + *
> + * Based on git-reset.sh, which is
> + *
> + * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
> + */
> +
> +#include "cache.h"
> +#include "run-command.h"
> +
> +int reset_index_file(const unsigned char *sha1, int is_hard_reset)
> +{
> +	int i = 0;
> +	const char *args[6];
> +
> +	args[i++] = "read-tree";
> +	args[i++] = "-v";
> +	args[i++] = "--reset";
> +	if (is_hard_reset)
> +		args[i++] = "-u";
> +	args[i++] = sha1_to_hex(sha1);
> +	args[i] = NULL;
> +
> +	return run_command_v_opt(args, RUN_GIT_CMD);
> +}

You might as well use unpack_trees() directly here, instead of running a 
separate command. In fact, you might skip making a function here, and just 
call unpack_trees() where you'd use it. (And maybe have a function to 
initialize a struct unpack_tree_options to some common defaults to make it 
easy to see what's being done.)

	-Daniel
*This .sig left intentionally blank*
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux