1. 21 6月, 2014 12 次提交
    • J
      git: avoid magic number with skip_prefix · 6d877803
      Jeff King 提交于
      After handling options, any leftover arguments should be
      commands. However, we pass through "--help" and "--version",
      so that we convert them into "git help" and "git version"
      respectively.
      
      This is a straightforward use of skip_prefix to avoid a
      magic number, but while we are there, it is worth adding a
      comment to explain this otherwise confusing behavior.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6d877803
    • J
      fetch-pack: refactor parsing in get_ack · 82e56767
      Jeff King 提交于
      There are several uses of the magic number "line+45" when
      parsing ACK lines from the server, and it's rather unclear
      why 45 is the correct number. We can make this more clear by
      keeping a running pointer as we parse, using skip_prefix to
      jump past the first "ACK ", then adding 40 to jump past
      get_sha1_hex (which is still magical, but hopefully 40 is
      less magical to readers of git code).
      
      Note that this actually puts us at line+44. The original
      required some character between the sha1 and further ACK
      flags (it is supposed to be a space, but we never enforced
      that). We start our search for flags at line+44, which
      meanas we are slightly more liberal than the old code.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      82e56767
    • J
      fast-import: refactor parsing of spaces · e814c39c
      Jeff King 提交于
      When we see a file change in a commit, we expect one of:
      
        1. A mark.
      
        2. An "inline" keyword.
      
        3. An object sha1.
      
      The handling of spaces is inconsistent between the three
      options. Option 1 calls a sub-function which checks for the
      space, but doesn't parse past it. Option 2 parses the space,
      then deliberately avoids moving the pointer past it. Option
      3 detects the space locally but doesn't move past it.
      
      This is confusing, because it looks like option 1 forgets to
      check for the space (it's just buried). And option 2 checks
      for "inline ", but only moves strlen("inline") characters
      forward, which looks like a bug but isn't.
      
      We can make this more clear by just having each branch move
      past the space as it is checked (and we can replace the
      doubled use of "inline" with a call to skip_prefix).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e814c39c
    • J
      stat_opt: check extra strlen call · 0539cc00
      Jeff King 提交于
      As in earlier commits, the diff option parser uses
      starts_with to find that an argument starts with "--stat-",
      and then adds strlen("stat-") to find the rest of the
      option.
      
      However, in this case the starts_with and the strlen are
      separated across functions, making it easy to call the
      latter without the former. Let's use skip_prefix instead of
      raw pointer arithmetic to catch such a case.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0539cc00
    • J
      daemon: use skip_prefix to avoid magic numbers · d12c24d2
      Jeff King 提交于
      Like earlier cases, we can use skip_prefix to avoid magic
      numbers that must match the length of starts_with prefixes.
      However, the numbers are a little more complicated here, as
      we keep parsing past the prefix. We can solve it by keeping
      a running pointer as we parse; its final value is the
      location we want.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d12c24d2
    • J
      fast-import: use skip_prefix for parsing input · 97313bef
      Jeff King 提交于
      Fast-import does a lot of parsing of commands and
      dispatching to sub-functions. For example, given "option
      foo", we might recognize "option " using starts_with, and
      then hand it off to parse_option() to do the rest.
      
      However, we do not let parse_option know that we have parsed
      the first part already. It gets the full buffer, and has to
      skip past the uninteresting bits. Some functions simply add
      a magic constant:
      
        char *option = command_buf.buf + 7;
      
      Others use strlen:
      
        char *option = command_buf.buf + strlen("option ");
      
      And others use strchr:
      
        char *option = strchr(command_buf.buf, ' ') + 1;
      
      All of these are brittle and easy to get wrong (especially
      given that the starts_with call and the code that assumes
      the presence of the prefix are far apart). Instead, we can
      use skip_prefix, and just pass each handler a pointer to its
      arguments.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      97313bef
    • J
      use skip_prefix to avoid repeating strings · 95b567c7
      Jeff King 提交于
      It's a common idiom to match a prefix and then skip past it
      with strlen, like:
      
        if (starts_with(foo, "bar"))
      	  foo += strlen("bar");
      
      This avoids magic numbers, but means we have to repeat the
      string (and there is no compiler check that we didn't make a
      typo in one of the strings).
      
      We can use skip_prefix to handle this case without repeating
      ourselves.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      95b567c7
    • J
      use skip_prefix to avoid magic numbers · ae021d87
      Jeff King 提交于
      It's a common idiom to match a prefix and then skip past it
      with a magic number, like:
      
        if (starts_with(foo, "bar"))
      	  foo += 3;
      
      This is easy to get wrong, since you have to count the
      prefix string yourself, and there's no compiler check if the
      string changes.  We can use skip_prefix to avoid the magic
      numbers here.
      
      Note that some of these conversions could be much shorter.
      For example:
      
        if (starts_with(arg, "--foo=")) {
      	  bar = arg + 6;
      	  continue;
        }
      
      could become:
      
        if (skip_prefix(arg, "--foo=", &bar))
      	  continue;
      
      However, I have left it as:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = v;
      	  continue;
        }
      
      to visually match nearby cases which need to actually
      process the string. Like:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = atoi(v);
      	  continue;
        }
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ae021d87
    • J
      transport-helper: avoid reading past end-of-string · 21a2d4ad
      Jeff King 提交于
      We detect the "import-marks" capability by looking for that
      string, but _without_ a trailing space. Then we skip past it
      using strlen("import-marks "), with a space. So if a remote
      helper gives us exactly "import-marks", we will read past
      the end-of-string by one character.
      
      This is unlikely to be a problem in practice, because such
      input is malformed in the first place, and because there is
      a good chance that the string has an extra NUL terminator
      one character after the original (because it formerly had a
      newline in it that we parsed off).
      
      We can fix it by using skip_prefix with "import-marks ",
      with the space. The other form appears to be a typo from
      a515ebe9 (transport-helper: implement marks location as
      capability, 2011-07-16); "import-marks" has never existed
      without an argument, and it should match the "export-marks"
      definition above.
      
      Speaking of which, we can also use skip_prefix in a few
      other places while we are in the function.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      21a2d4ad
    • J
      fast-import: fix read of uninitialized argv memory · ff45c0d4
      Jeff King 提交于
      Fast-import shares code between its command-line parser and
      the "option" command. To do so, it strips the "--" from any
      command-line options and passes them to the option parser.
      However, it does not confirm that the option even begins
      with "--" before blindly passing "arg + 2".
      
      It does confirm that the option starts with "-", so the only
      affected case was:
      
        git fast-import -
      
      which would read uninitialized memory after the argument. We
      can fix it by using skip_prefix and checking the result. As
      a bonus, this gets rid of some magic numbers.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ff45c0d4
    • J
      apply: use skip_prefix instead of raw addition · ce2ecf29
      Jeff King 提交于
      A submodule diff generally has content like:
      
        -Subproject commit [0-9a-f]{40}
        +Subproject commit [0-9a-f]{40}
      
      When we are using "git apply --index" with a submodule, we
      first apply the textual diff, and then parse that result to
      figure out the new sha1.
      
      If the diff has bogus input like:
      
        -Subproject commit 1234567890123456789012345678901234567890
        +bogus
      
      we will parse the "bogus" portion. Our parser assumes that
      the buffer starts with "Subproject commit", and blindly
      skips past it using strlen(). This can cause us to read
      random memory after the buffer.
      
      This problem was unlikely to have come up in practice (since
      it requires a malformed diff), and even when it did, we
      likely noticed the problem anyway as the next operation was
      to call get_sha1_hex on the random memory.
      
      However, we can easily fix it by using skip_prefix to notice
      the parsing error.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ce2ecf29
    • J
      refactor skip_prefix to return a boolean · cf4fff57
      Jeff King 提交于
      The skip_prefix() function returns a pointer to the content
      past the prefix, or NULL if the prefix was not found. While
      this is nice and simple, in practice it makes it hard to use
      for two reasons:
      
        1. When you want to conditionally skip or keep the string
           as-is, you have to introduce a temporary variable.
           For example:
      
             tmp = skip_prefix(buf, "foo");
             if (tmp)
      	       buf = tmp;
      
        2. It is verbose to check the outcome in a conditional, as
           you need extra parentheses to silence compiler
           warnings. For example:
      
             if ((cp = skip_prefix(buf, "foo"))
      	       /* do something with cp */
      
      Both of these make it harder to use for long if-chains, and
      we tend to use starts_with() instead. However, the first line
      of "do something" is often to then skip forward in buf past
      the prefix, either using a magic constant or with an extra
      strlen(3) (which is generally computed at compile time, but
      means we are repeating ourselves).
      
      This patch refactors skip_prefix() to return a simple boolean,
      and to provide the pointer value as an out-parameter. If the
      prefix is not found, the out-parameter is untouched. This
      lets you write:
      
        if (skip_prefix(arg, "foo ", &arg))
      	  do_foo(arg);
        else if (skip_prefix(arg, "bar ", &arg))
      	  do_bar(arg);
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cf4fff57
  2. 19 6月, 2014 3 次提交
  3. 17 6月, 2014 25 次提交
    • J
      Third batch for 2.1 · cb682f8c
      Junio C Hamano 提交于
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cb682f8c
    • J
      Merge branch 'ib/test-selectively-run' · 7e1a5381
      Junio C Hamano 提交于
      Allow specifying only certain individual test pieces to be run
      using a range notation (e.g. "t1234-test.sh --run='1-4 6 8 9-'").
      
      * ib/test-selectively-run:
        t0000-*.sh: fix the GIT_SKIP_TESTS sub-tests
        test-lib: '--run' to run only specific tests
        test-lib: tests skipped by GIT_SKIP_TESTS say so
        test-lib: document short options in t/README
      7e1a5381
    • J
      Merge branch 'ta/string-list-init' · c6d3abbf
      Junio C Hamano 提交于
      * ta/string-list-init:
        string-list: spell all values out that are given to a string_list initializer
      c6d3abbf
    • J
      Merge branch 'jm/dedup-test-config' · bbfa0cc7
      Junio C Hamano 提交于
      * jm/dedup-test-config:
        t/t7810-grep.sh: remove duplicate test_config()
      bbfa0cc7
    • J
      Merge branch 'dt/refs-check-refname-component-optim' · ae7dd1a4
      Junio C Hamano 提交于
      * dt/refs-check-refname-component-optim:
        refs.c: optimize check_refname_component()
      ae7dd1a4
    • J
      Merge branch 'sk/test-cmp-bin' · c651ccc9
      Junio C Hamano 提交于
      * sk/test-cmp-bin:
        t5000, t5003: do not use test_cmp to compare binary files
      c651ccc9
    • J
      Merge branch 'sh/enable-preloadindex' · 96b29bde
      Junio C Hamano 提交于
      * sh/enable-preloadindex:
        environment.c: enable core.preloadindex by default
      96b29bde
    • J
      Merge branch 'rs/read-ref-at' · bb0ced75
      Junio C Hamano 提交于
      * rs/read-ref-at:
        refs.c: change read_ref_at to use the reflog iterators
      bb0ced75
    • J
      Merge branch 'jk/error-resolve-conflict-advice' · d0d5ba7e
      Junio C Hamano 提交于
      * jk/error-resolve-conflict-advice:
        error_resolve_conflict: drop quotations around operation
        error_resolve_conflict: rewrap advice message
      d0d5ba7e
    • J
      Merge branch 'rs/pack-objects-no-unnecessary-realloc' · 57a2eee9
      Junio C Hamano 提交于
      Avoid unnecessary copy of previous contents when extending the
      hashtable used in pack-objects.
      
      * rs/pack-objects-no-unnecessary-realloc:
        pack-objects: use free()+xcalloc() instead of xrealloc()+memset()
      57a2eee9
    • J
      Merge branch 'lt/log-auto-decorate' · 3009afd5
      Junio C Hamano 提交于
      * lt/log-auto-decorate:
        git log: support "auto" decorations
      3009afd5
    • J
      Merge branch 'jm/doc-wording-tweaks' · 668668ad
      Junio C Hamano 提交于
      * jm/doc-wording-tweaks:
        Documentation: wording fixes in the user manual and glossary
      668668ad
    • J
      Merge branch 'jm/format-patch-mail-sig' · f18871dc
      Junio C Hamano 提交于
      * jm/format-patch-mail-sig:
        format-patch: add "--signature-file=<file>" option
        format-patch: make newline after signature conditional
      f18871dc
    • J
      Merge branch 'jk/http-errors' · 2075a0c2
      Junio C Hamano 提交于
      Propagate the error messages from the webserver better to the
      client coming over the HTTP transport.
      
      * jk/http-errors:
        http: default text charset to iso-8859-1
        remote-curl: reencode http error messages
        strbuf: add strbuf_reencode helper
        http: optionally extract charset parameter from content-type
        http: extract type/subtype portion of content-type
        t5550: test display of remote http error messages
        t/lib-httpd: use write_script to copy CGI scripts
        test-lib: preserve GIT_CURL_VERBOSE from the environment
      2075a0c2
    • J
      Merge branch 'ow/config-mailmap-pathname' · c37d3269
      Junio C Hamano 提交于
      mailmap.file configuration names a pathname, hence should honor
      ~/path and ~user/path as its value.
      
      * ow/config-mailmap-pathname:
        config: respect '~' and '~user' in mailmap.file
      c37d3269
    • J
      Merge branch 'fc/remote-helper-refmap' · c9fc3a6a
      Junio C Hamano 提交于
      Allow remote-helper/fast-import based transport to rename the refs
      while transferring the history.
      
      * fc/remote-helper-refmap:
        transport-helper: remove unnecessary strbuf resets
        transport-helper: add support to delete branches
        fast-export: add support to delete refs
        fast-import: add support to delete refs
        transport-helper: add support to push symbolic refs
        transport-helper: add support for old:new refspec
        fast-export: add new --refspec option
        fast-export: improve argument parsing
      c9fc3a6a
    • J
      Merge branch 'nd/daemonize-gc' · 1a81f6ce
      Junio C Hamano 提交于
      "git gc --auto" was recently changed to run in the background to
      give control back early to the end-user sitting in front of the
      terminal, but it forgot that housekeeping involving reflogs should
      be done without other processes competing for accesses to the refs.
      
      * nd/daemonize-gc:
        gc --auto: do not lock refs in the background
      1a81f6ce
    • J
      Merge branch 'jm/t9138-style-fix' · 8dbd3133
      Junio C Hamano 提交于
      * jm/t9138-style-fix:
        t9138-git-svn-authors-prog.sh fixups
      8dbd3133
    • J
      Merge branch 'jm/instaweb-apache-24' · bf2941be
      Junio C Hamano 提交于
      * jm/instaweb-apache-24:
        git-instaweb: add support for Apache 2.4
      bf2941be
    • J
      Merge branch 'jl/remote-rm-prune' · 474df928
      Junio C Hamano 提交于
      "git remote rm" and "git remote prune" can involve removing many
      refs at once, which is not a very efficient thing to do when very
      many refs exist in the packed-refs file.
      
      * jl/remote-rm-prune:
        remote prune: optimize "dangling symref" check/warning
        remote: repack packed-refs once when deleting multiple refs
        remote rm: delete remote configuration as the last
      474df928
    • J
      Merge branch 'jk/complete-merge-pull' · 5cf2c571
      Junio C Hamano 提交于
      The completion code did not know about quite a few options that are
      common between "git merge" and "git pull", and a couple of options
      unique to "git merge".
      
      * jk/complete-merge-pull:
        completion: add missing options for git-merge
        completion: add a note that merge options are shared
      5cf2c571
    • J
      Merge branch 'bg/xcalloc-nmemb-then-size' · a634a6d2
      Junio C Hamano 提交于
      Like calloc(3), xcalloc() takes nmemb and then size.
      
      * bg/xcalloc-nmemb-then-size:
        transport-helper.c: rearrange xcalloc arguments
        remote.c: rearrange xcalloc arguments
        reflog-walk.c: rearrange xcalloc arguments
        pack-revindex.c: rearrange xcalloc arguments
        notes.c: rearrange xcalloc arguments
        imap-send.c: rearrange xcalloc arguments
        http-push.c: rearrange xcalloc arguments
        diff.c: rearrange xcalloc arguments
        config.c: rearrange xcalloc arguments
        commit.c: rearrange xcalloc arguments
        builtin/remote.c: rearrange xcalloc arguments
        builtin/ls-remote.c: rearrange xcalloc arguments
      a634a6d2
    • J
      Merge branch 'jl/status-added-submodule-is-never-ignored' · 6d681f0a
      Junio C Hamano 提交于
      submodule.*.ignore and diff.ignoresubmodules are used to ignore all
      submodule changes in "diff" output, but it can be confusing to
      apply these configuration values to status and commit.
      
      This is a backward-incompatible change, but should be so in a good
      way (aka bugfix).
      
      * jl/status-added-submodule-is-never-ignored:
        commit -m: commit staged submodules regardless of ignore config
        status/commit: show staged submodules regardless of ignore config
      6d681f0a
    • J
      Merge branch 'cb/byte-order' · 83a4904f
      Junio C Hamano 提交于
      Compatibility enhancement for Solaris.
      
      * cb/byte-order:
        compat/bswap.h: fix endianness detection
        compat/bswap.h: restore preference __BIG_ENDIAN over BIG_ENDIAN
        compat/bswap.h: detect endianness on more platforms that don't use BYTE_ORDER
      83a4904f
    • J
      Merge branch 'jk/strbuf-tolower' · b4bba8de
      Junio C Hamano 提交于
      * jk/strbuf-tolower:
        strbuf: add strbuf_tolower function
      b4bba8de