]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'mg/more-textconv'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2013 20:21:30 +0000 (13:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2013 20:21:31 +0000 (13:21 -0700)
Make "git grep" and "git show" pay attention to --textconv when
dealing with blob objects.

* mg/more-textconv:
  grep: honor --textconv for the case rev:path
  grep: allow to use textconv filters
  t7008: demonstrate behavior of grep with textconv
  cat-file: do not die on --textconv without textconv filters
  show: honor --textconv for blobs
  diff_opt: track whether flags have been set explicitly
  t4030: demonstrate behavior of show with textconv

1  2 
Documentation/git-grep.txt
builtin/cat-file.c
builtin/grep.c
builtin/log.c
diff.c
diff.h
object.c
object.h
t/t4030-diff-textconv.sh
t/t8007-cat-file-textconv.sh

Simple merge
Simple merge
diff --cc builtin/grep.c
Simple merge
diff --cc builtin/log.c
Simple merge
diff --cc diff.c
Simple merge
diff --cc diff.h
index 44092c2176468257644a19f787038a1ff3033eaa,e995ae12fee89605b0350b95ea782ed09b303a42..e34232501ee8e56a1d245da1c4f95ed8b928a837
--- 1/diff.h
--- 2/diff.h
+++ b/diff.h
@@@ -109,10 -110,7 +110,11 @@@ struct diff_options 
        const char *single_follow;
        const char *a_prefix, *b_prefix;
        unsigned flags;
+       unsigned touched_flags;
 +
 +      /* diff-filter bits */
 +      unsigned int filter;
 +
        int use_color;
        int context;
        int interhunkcontext;
diff --cc object.c
index 5f792cbfd38c0b30d763902ba5f9399992ddab89,c8ffc9e006e42d75f0c3632c378133b4dfbad6a0..584f7acb36b68d17678b3fd6251105241794ea48
+++ b/object.c
@@@ -262,18 -255,7 +262,16 @@@ int object_list_contains(struct object_
        return 0;
  }
  
- void add_object_array(struct object *obj, const char *name, struct object_array *array)
- {
-       add_object_array_with_mode(obj, name, array, S_IFINVALID);
- }
 -static void add_object_array_with_mode_context(struct object *obj, const char *name, struct object_array *array, unsigned mode, struct object_context *context)
 +/*
 + * A zero-length string to which object_array_entry::name can be
 + * initialized without requiring a malloc/free.
 + */
 +static char object_array_slopbuf[1];
 +
- void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
++static void add_object_array_with_mode_context(struct object *obj, const char *name,
++                                             struct object_array *array,
++                                             unsigned mode,
++                                             struct object_context *context)
  {
        unsigned nr = array->nr;
        unsigned alloc = array->alloc;
                array->alloc = alloc;
                array->objects = objects;
        }
 -      objects[nr].item = obj;
 -      objects[nr].name = name;
 -      objects[nr].mode = mode;
 -      objects[nr].context = context;
 +      entry = &objects[nr];
 +      entry->item = obj;
 +      if (!name)
 +              entry->name = NULL;
 +      else if (!*name)
 +              /* Use our own empty string instead of allocating one: */
 +              entry->name = object_array_slopbuf;
 +      else
 +              entry->name = xstrdup(name);
 +      entry->mode = mode;
++      entry->context = context;
        array->nr = ++nr;
  }
  
 -void object_array_remove_duplicates(struct object_array *array)
+ void add_object_array(struct object *obj, const char *name, struct object_array *array)
+ {
+       add_object_array_with_mode(obj, name, array, S_IFINVALID);
+ }
+ void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
+ {
+       add_object_array_with_mode_context(obj, name, array, mode, NULL);
+ }
+ void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context)
+ {
+       if (context)
+               add_object_array_with_mode_context(obj, name, array, context->mode, context);
+       else
+               add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
+ }
 +void object_array_filter(struct object_array *array,
 +                       object_array_each_func_t want, void *cb_data)
  {
 -      unsigned int ref, src, dst;
 +      unsigned nr = array->nr, src, dst;
        struct object_array_entry *objects = array->objects;
  
 -      for (ref = 0; ref + 1 < array->nr; ref++) {
 -              for (src = ref + 1, dst = src;
 -                   src < array->nr;
 -                   src++) {
 -                      if (!strcmp(objects[ref].name, objects[src].name))
 -                              continue;
 +      for (src = dst = 0; src < nr; src++) {
 +              if (want(&objects[src], cb_data)) {
                        if (src != dst)
                                objects[dst] = objects[src];
                        dst++;
diff --cc object.h
index 2ff68c52dd48842a188eb8f0c9b1e12ff27fae37,695847dfd4812c510c9766303ae34425bcfc6b29..dc5df8ce1d9579a28477f91300aa7a49f37ad4e4
+++ b/object.h
@@@ -11,14 -11,9 +11,15 @@@ struct object_array 
        unsigned int alloc;
        struct object_array_entry {
                struct object *item;
 -              const char *name;
 +              /*
 +               * name or NULL.  If non-NULL, the memory pointed to
 +               * is owned by this object *except* if it points at
 +               * object_array_slopbuf, which is a static copy of the
 +               * empty string.
 +               */
 +              char *name;
                unsigned mode;
+               struct object_context *context;
        } *objects;
  };
  
@@@ -91,22 -86,8 +92,23 @@@ int object_list_contains(struct object_
  /* Object array handling .. */
  void add_object_array(struct object *obj, const char *name, struct object_array *array);
  void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
 -void object_array_remove_duplicates(struct object_array *);
+ void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context);
 +
 +typedef int (*object_array_each_func_t)(struct object_array_entry *, void *);
 +
 +/*
 + * Apply want to each entry in array, retaining only the entries for
 + * which the function returns true.  Preserve the order of the entries
 + * that are retained.
 + */
 +void object_array_filter(struct object_array *array,
 +                       object_array_each_func_t want, void *cb_data);
 +
 +/*
 + * Remove from array all but the first entry with a given name.
 + * Warning: this function uses an O(N^2) algorithm.
 + */
 +void object_array_remove_duplicates(struct object_array *array);
  
  void clear_object_flags(unsigned flags);
  
Simple merge
index b95e102891db65c184a2ee3137f1b3e20cdab2db,83c663678f5700f994da1508dbfb4529597b751d..eacd49ade636f5be6166e05d4e200b9a324073be
@@@ -70,26 -68,20 +66,20 @@@ test_expect_success 'cat-file --textcon
        test_cmp expected result
  '
  
 -test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
 +test_expect_success 'cat-file without --textconv (symlink)' '
+       printf "%s" "one.bin" >expected &&
        git cat-file blob :symlink.bin >result &&
-       printf "%s" "one.bin" >expected
        test_cmp expected result
  '
  
  
 -test_expect_success SYMLINKS 'cat-file --textconv on index (symlink)' '
 +test_expect_success 'cat-file --textconv on index (symlink)' '
-       ! git cat-file --textconv :symlink.bin 2>result &&
-       cat >expected <<\EOF &&
- fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
- EOF
+       git cat-file --textconv :symlink.bin >result &&
        test_cmp expected result
  '
  
 -test_expect_success SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
 +test_expect_success 'cat-file --textconv on HEAD (symlink)' '
-       ! git cat-file --textconv HEAD:symlink.bin 2>result &&
-       cat >expected <<EOF &&
- fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
- EOF
+       git cat-file --textconv HEAD:symlink.bin >result &&
        test_cmp expected result
  '