Merge branch 'lt/diff' into next
authorJunio C Hamano <junkio@cox.net>
Sun, 14 May 2006 23:39:14 +0000 (16:39 -0700)
committerJunio C Hamano <junkio@cox.net>
Sun, 14 May 2006 23:39:14 +0000 (16:39 -0700)
* lt/diff:
git diff: support "-U" and "--unified" options properly
include header to define uint32_t, necessary on Mac OS X

combine-diff.c
diff.c
diff.h
pack-objects.c
sha1_file.c
index 8a8fe3863a002ea6b62a760d5413dfe0fd0ffde7..64b20cce2427fcf0cd9565f5e24efce78abb0088 100644 (file)
@@ -608,6 +608,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
        int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
        mmfile_t result_file;
 
+       context = opt->context;
        /* Read the result of merge first */
        if (!working_tree_file)
                result = grab_blob(elem->sha1, &result_size);
diff --git a/diff.c b/diff.c
index 7a7b839e56ac1ba2ed0b770a047aaf07bce23722..be925a3a39d4cdb13c1e728e86438dde9fd5165e 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -558,7 +558,7 @@ static void builtin_diff(const char *name_a,
 
                ecbdata.label_path = lbl;
                xpp.flags = XDF_NEED_MINIMAL;
-               xecfg.ctxlen = 3;
+               xecfg.ctxlen = o->context;
                xecfg.flags = XDL_EMIT_FUNCNAMES;
                if (!diffopts)
                        ;
@@ -1182,6 +1182,7 @@ void diff_setup(struct diff_options *options)
        options->line_termination = '\n';
        options->break_opt = -1;
        options->rename_limit = -1;
+       options->context = 3;
 
        options->change = diff_change;
        options->add_remove = diff_addremove;
@@ -1222,11 +1223,60 @@ int diff_setup_done(struct diff_options *options)
        return 0;
 }
 
+int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
+{
+       char c, *eq;
+       int len;
+
+       if (*arg != '-')
+               return 0;
+       c = *++arg;
+       if (!c)
+               return 0;
+       if (c == arg_short) {
+               c = *++arg;
+               if (!c)
+                       return 1;
+               if (val && isdigit(c)) {
+                       char *end;
+                       int n = strtoul(arg, &end, 10);
+                       if (*end)
+                               return 0;
+                       *val = n;
+                       return 1;
+               }
+               return 0;
+       }
+       if (c != '-')
+               return 0;
+       arg++;
+       eq = strchr(arg, '=');
+       if (eq)
+               len = eq - arg;
+       else
+               len = strlen(arg);
+       if (!len || strncmp(arg, arg_long, len))
+               return 0;
+       if (eq) {
+               int n;
+               char *end;
+               if (!isdigit(*++eq))
+                       return 0;
+               n = strtoul(eq, &end, 10);
+               if (*end)
+                       return 0;
+               *val = n;
+       }
+       return 1;
+}
+
 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 {
        const char *arg = av[0];
        if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
                options->output_format = DIFF_FORMAT_PATCH;
+       else if (opt_arg(arg, 'U', "unified", &options->context))
+               options->output_format = DIFF_FORMAT_PATCH;
        else if (!strcmp(arg, "--patch-with-raw")) {
                options->output_format = DIFF_FORMAT_PATCH;
                options->with_raw = 1;
diff --git a/diff.h b/diff.h
index d052608404314880652561e4296e05e9da3f96ca..bef586d8502f6e78b95cce15456704572ffe8c00 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -32,6 +32,7 @@ struct diff_options {
                 full_index:1,
                 silent_on_remove:1,
                 find_copies_harder:1;
+       int context;
        int break_opt;
        int detect_rename;
        int line_termination;
index 1b9e7a1cb987627f762f5fb6f91b3df30ec93605..5466b1516788c878bfd3377f74dab40f73355127 100644 (file)
@@ -10,6 +10,7 @@
 #include "tree-walk.h"
 #include <sys/time.h>
 #include <signal.h>
+#include <stdint.h>
 
 static const char pack_usage[] = "git-pack-objects [-q] [--no-reuse-delta] [--non-empty] [--local] [--incremental] [--window=N] [--depth=N] {--stdout | base-name} < object-list";
 
index 631a605201e3a737e8e3db25f85f01a228b01282..3372ebcdcac0d36b81663f958784e8a1ec84b900 100644 (file)
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree.h"
+#include <stdint.h>
 
 #ifndef O_NOATIME
 #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))