Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Dec 29, 2014
  1. @pclouds @gitster

    attr: avoid heavy work when we know the specified attr is not defined

    pclouds authored gitster committed
    If we have never seen attr 'X' in any .gitattributes file we have
    examined so far, we can be sure that 'X' is not defined. So no need to
    go over all the attr stack to look for attr 'X'. This is the purpose
    behind this new field maybe_real.
    
    This optimization breaks down if macros are involved because we can't
    know for sure what macro would expand to 'X' at attr parsing time. But
    if we go the pessimistic way and assume all macros are expanded, we hit
    the builtin "binary" macro. At least the "diff" attr defined in this
    macro will disable this optimization for git-grep. So we wait until
    any attr lines _may_ reference to a macro before we turn this off.
    
    In git.git, this reduces the number of fill_one() call for "git grep
    abcdefghi" from ~5348 to 2955. The optimization stops when it reads
    t/.gitattributes, which uses 'binary' macro. We could probably reduce
    it further by limiting the 'binary' reference to t/ and subdirs only
    in this case.
    
    "git grep" is actually a good example to justify this patch. The
    command checks "diff" attribute on every file. People usually don't
    define this attribute. But they pay the attr lookup penalty anyway
    without this patch, proportional to the number of attr lines they have
    in repo.
    
    Helped-by: Junio C Hamano <gitster@pobox.com>
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @pclouds @gitster

    attr: do not attempt to expand when we know it's not a macro

    pclouds authored gitster committed
    Keep track of all recognized macros in the new "maybe_macro" field.
    If this field is true, it _may_ be a macro (depending on what's in the
    current attr stack). But if the field is false, it's definitely not a
    macro, no need to go through the whole attr stack in macroexpand_one()
    to search for one.
    
    Without this, "git grep abcdefghi" on git.git hits the inner loop in
    macroexpand_one() 2481 times. With this, it's 66 times.
    
    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  3. @pclouds @gitster

    attr.c: rename arg name attr_nr to avoid shadowing the global one

    pclouds authored gitster committed
    Helped-by: Junio C Hamano <gitster@pobox.com>
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 16, 2013
  1. @pclouds @gitster

    attr: avoid calling find_basename() twice per path

    pclouds authored gitster committed
    find_basename() is only used inside collect_all_attrs(), called once
    in prepare_attr_stack, then again after prepare_attr_stack()
    returns. Both calls return exact same value. Reorder the code to do
    the same task once. Also avoid strlen() because we knows the length
    after finding basename.
    
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 15, 2013
  1. @pclouds @gitster

    attr: make it build with DEBUG_ATTR again

    pclouds authored gitster committed
    Commit 82dce99 (attr: more matching optimizations from .gitignore -
    2012-10-15) changed match_attr structure but it did not update
    DEBUG_ATTR-specific code. This fixes it.
    
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @pclouds @gitster

    attr: fix off-by-one directory component length calculation

    pclouds authored gitster committed
    94bc671 (Add directory pattern matching to attributes - 2012-12-08)
    uses find_basename() to calculate the length of directory part in
    prepare_attr_stack. This function expects the directory without the
    trailing slash (as "origin" field in match_attr struct is without the
    trailing slash). find_basename() includes the trailing slash and
    confuses push/pop algorithm.
    
    Consider path = "abc/def" and the push down code:
    
    	while (1) {
    		len = strlen(attr_stack->origin);
    		if (dirlen <= len)
    			break;
    		cp = memchr(path + len + 1, '/', dirlen - len - 1);
    		if (!cp)
    			cp = path + dirlen;
    
    dirlen is 4, not 3, without this patch. So when attr_stack->origin is
    "abc", it'll miss the exit condition because 4 <= 3 is wrong. It'll
    then try to push "abc/" down the attr stack (because "cp" would be
    NULL). So we have both "abc" and "abc/" in the stack.
    
    Next time when "abc/ghi" is checked, "abc/" is popped out because of
    the off-by-one dirlen, only to be pushed back in again by the above
    code. This repeats for all files in the same directory. Which means
    at least one failed open syscall per file, or more if .gitattributes
    exists.
    
    This is the perf result with 10 runs on git.git:
    
    Test                                     94bc671^          94bc671                   HEAD
    ----------------------------------------------------------------------------------------------------------
    7810.1: grep worktree, cheap regex       0.02(0.01+0.04)   0.05(0.03+0.05) +150.0%   0.02(0.01+0.04) +0.0%
    7810.2: grep worktree, expensive regex   0.25(0.94+0.01)   0.26(0.94+0.02) +4.0%     0.25(0.93+0.02) +0.0%
    7810.3: grep --cached, cheap regex       0.11(0.10+0.00)   0.12(0.10+0.02) +9.1%     0.10(0.10+0.00) -9.1%
    7810.4: grep --cached, expensive regex   0.61(0.60+0.01)   0.62(0.61+0.01) +1.6%     0.61(0.60+0.00) +0.0%
    
    Reported-by: Ross Lagerwall <rosslagerwall@gmail.com>
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Oct 15, 2012
  1. @pclouds @gitster

    attr: more matching optimizations from .gitignore

    pclouds authored gitster committed
    .gitattributes and .gitignore share the same pattern syntax but has
    separate matching implementation. Over the years, ignore's
    implementation accumulates more optimizations while attr's stays the
    same.
    
    This patch reuses the core matching functions that are also used by
    excluded_from_list. excluded_from_list and path_matches can't be
    merged due to differences in exclude and attr, for example:
    
    * "!pattern" syntax is forbidden in .gitattributes.  As an attribute
      can be unset (i.e. set to a special value "false") or made back to
      unspecified (i.e. not even set to "false"), "!pattern attr" is unclear
      which one it means.
    
    * we support attaching attributes to directories, but git-core
      internally does not currently make use of attributes on
      directories.
    
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Oct 5, 2012
  1. @pclouds @gitster

    attr: avoid searching for basename on every match

    pclouds authored gitster committed
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @pclouds @gitster

    attr: avoid strlen() on every match

    pclouds authored gitster committed
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Apr 18, 2009
  1. @pclouds @gitster

    attr: add GIT_ATTR_INDEX "direction"

    pclouds authored gitster committed
    This instructs attr mechanism, not to look into working .gitattributes
    at all. Needed by tools that does not handle working directory, such
    as "git archive".
    
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Something went wrong with that request. Please try again.