From ac1b3d1248f36b26c2eab55022b9a54bde36b1ee Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 20 Oct 2005 21:05:05 -0700 Subject: Split up tree diff functions into tree-diff.c library This makes the tree diff functionality independent of the "git-diff-tree" program, by splitting the core functionality up into a library file. This will be needed for when we teach git-rev-list to only follow a specified set of pathnames, rather than the global revision history. Most of it is a fairly straightforward code move, but it also involves some calling convention cleanup, and moving some of the static variables from diff-tree.c into the options structure. The actual tree change callback routines also become paramterized by the diff_options structure, allowing the library functionality to do something else than just show the diff on stdout. Right now the only user of this functionality remains git-diff-tree itself. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'diff.h') diff --git a/diff.h b/diff.h index 2f4a7b463b..51155479a4 100644 --- a/diff.h +++ b/diff.h @@ -8,11 +8,31 @@ (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \ S_ISLNK(mode) ? S_IFLNK : S_IFDIR) +struct tree_desc { + void *buf; + unsigned long size; +}; + +struct diff_options; + +typedef void (*change_fn_t)(struct diff_options *options, + unsigned old_mode, unsigned new_mode, + const unsigned char *old_sha1, + const unsigned char *new_sha1, + const char *base, const char *path); + +typedef void (*add_remove_fn_t)(struct diff_options *options, + int addremove, unsigned mode, + const unsigned char *sha1, + const char *base, const char *path); + struct diff_options { const char **paths; const char *filter; const char *orderfile; const char *pickaxe; + unsigned recursive:1, + tree_in_recursive:1; int break_opt; int detect_rename; int find_copies_harder; @@ -23,8 +43,17 @@ struct diff_options { int reverse_diff; int rename_limit; int setup; + + change_fn_t change; + add_remove_fn_t add_remove; }; +extern void diff_tree_setup_paths(const char **paths); +extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2, + const char *base, struct diff_options *opt); +extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, + const char *base, struct diff_options *opt); + extern void diff_addremove(struct diff_options *, int addremove, unsigned mode, -- cgit v1.3 From 50b8e355b64c93a71d5008557e15f52c032240ff Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Fri, 28 Oct 2005 13:04:49 -0400 Subject: Documentation changes to recursive option for git-diff-tree Update docs and usages regarding '-r' recursive option for git-diff-tree. Remove '-r' from common diff options, mention it only for git-diff-tree. Remove one extraneous use of '-r' with git-diff-files in get-merge.sh. Sync the synopsis and usage string for git-diff-tree. Signed-off-by: Chris Shoemaker Signed-off-by: Junio C Hamano --- Documentation/git-diff-tree.txt | 5 ++++- diff-tree.c | 6 ++++-- diff.h | 1 - git-merge.sh | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'diff.h') diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index dcfb9e18c7..f57c8d0d81 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -8,7 +8,7 @@ git-diff-tree - Compares the content and mode of blobs found via two tree object SYNOPSIS -------- -'git-diff-tree' [--stdin] [-m] [-s] [-v] [--pretty] [-t] [] [] [...] +'git-diff-tree' [--stdin] [-m] [-s] [-v] [--pretty] [-t] [-r] [--root] [] [] [...] DESCRIPTION ----------- @@ -33,6 +33,9 @@ include::diff-options.txt[] Note that this parameter does not provide any wildcard or regexp features. +-r:: + recurse into sub-trees + -t:: show tree entry itself as well as subtrees. Implies -r. diff --git a/diff-tree.c b/diff-tree.c index 382011a2a6..ed323d877c 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -149,8 +149,10 @@ static int diff_tree_stdin(char *line) } static const char diff_tree_usage[] = -"git-diff-tree [--stdin] [-m] [-s] [-v] [--pretty] [-t] " -"[] " +"git-diff-tree [--stdin] [-m] [-s] [-v] [--pretty] [-t] [-r] [--root] " +"[] [] [...]\n" +" -r diff recursively\n" +" --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP; int main(int argc, const char **argv) diff --git a/diff.h b/diff.h index 51155479a4..12590791cb 100644 --- a/diff.h +++ b/diff.h @@ -91,7 +91,6 @@ extern void diffcore_std_no_resolve(struct diff_options *); #define COMMON_DIFF_OPTIONS_HELP \ "\ncommon diff options:\n" \ -" -r diff recursively (only meaningful in diff-tree)\n" \ " -z output diff-raw with lines terminated with NUL.\n" \ " -p output patch format.\n" \ " -u synonym for -p.\n" \ diff --git a/git-merge.sh b/git-merge.sh index 3457a96cfd..6ad96ebfbb 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -25,7 +25,7 @@ dropsave() { savestate() { # Stash away any local modifications. - git-diff-index -r -z --name-only $head | + git-diff-index -z --name-only $head | cpio -0 -o >"$GIT_DIR/MERGE_SAVE" } -- cgit v1.3