Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Commits on Apr 29, 2015
  1. @peff @gitster

    filter-branch: avoid passing commit message through sed

    peff committed with gitster
    On some systems (like OS X), if sed encounters input without
    a trailing newline, it will silently add it. As a result,
    "git filter-branch" on such systems may silently rewrite
    commit messages that omit a trailing newline. Even though
    this is not something we generate ourselves with "git
    commit", it's better for filter-branch to preserve the
    original data as closely as possible.
    We're using sed here only to strip the header fields from
    the commit object. We can accomplish the same thing with a
    shell loop. Since shell "read" calls are slow (usually one
    syscall per byte), we use "cat" once we've skipped past the
    header. Depending on the size of your commit messages, this
    is probably faster (you pay the cost to fork, but then read
    the data in saner-sized chunks). This idea is shamelessly
    stolen from Junio.
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Commits on Aug 29, 2013
  1. @peff @gitster

    write_index: optionally allow broken null sha1s

    peff committed with gitster
    Commit 4337b58 (do not write null sha1s to on-disk index,
    2012-07-28) added a safety check preventing git from writing
    null sha1s into the index. The intent was to catch errors in
    other parts of the code that might let such an entry slip
    into the index (or worse, a tree).
    Some existing repositories may have invalid trees that
    contain null sha1s already, though.  Until 4337b58, a common
    way to clean this up would be to use git-filter-branch's
    index-filter to repair such broken entries.  That now fails
    when filter-branch tries to write out the index.
    Introduce a GIT_ALLOW_NULL_SHA1 environment variable to
    relax this check and make it easier to recover from such a
    It is tempting to not involve filter-branch in this commit
    at all, and instead require the user to manually invoke
    	GIT_ALLOW_NULL_SHA1=1 git filter-branch ...
    to perform an index-filter on a history with trees with null
    sha1s.  That would be slightly safer, but requires some
    specialized knowledge from the user.  So let's set the
    GIT_ALLOW_NULL_SHA1 variable automatically when checking out
    the to-be-filtered trees.  Advice on using filter-branch to
    remove such entries already exists on places like
    stackoverflow, and this patch makes it Just Work again on
    recent versions of git.
    Further commands that touch the index will still notice and
    fail, unless they actually remove the broken entries.  A
    filter-branch whose filters do not touch the index at all
    will not error out (since we complain of the null sha1 only
    on writing, not when making a tree out of the index), but
    this is acceptable, as we still print a loud warning, so the
    problem is unlikely to go unnoticed.
    Signed-off-by: Jeff King <>
    Reviewed-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
Commits on Apr 2, 2013
  1. @peff @gitster

    filter-branch: return to original dir after filtering

    peff committed with gitster
    The first thing filter-branch does is to create a temporary
    directory, either ".git-rewrite" in the current directory
    (which may be the working tree or the repository if bare),
    or in a directory specified by "-d". We then chdir to
    $tempdir/t as our temporary working directory in which to run
    tree filters.
    After finishing the filter, we then attempt to go back to
    the original directory with "cd ../..". This works in the
    .git-rewrite case, but if "-d" is used, we end up in a
    random directory. The only thing we do after this chdir is
    to run git-read-tree, but that means that:
      1. The working directory is not updated to reflect the
         filtered history.
      2. We dump random files into "$tempdir/.." (e.g., if you
         use "-d /tmp/foo", we dump junk into /tmp).
    Fix it by recording the full path to the original directory
    and returning there explicitly.
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Commits on Oct 18, 2012
  1. @peff @gitster

    filter-branch: use git-sh-setup's ident parsing functions

    peff committed with gitster
    This saves us some code, but it also reduces the number of
    processes we start for each filtered commit. Since we can
    parse both author and committer in the same sed invocation,
    we save one process. And since the new interface avoids tr,
    we save 4 processes.
    It also avoids using "tr", which has had some odd
    portability problems reported with from Solaris's xpg6
    We also tweak one of the tests in t7003 to double-check that
    we are properly exporting the variables (because
    exports GIT_AUTHOR_NAME, it will be automatically exported
    in subprograms. We override this to make sure that
    filter-branch handles it properly itself).
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Commits on Sep 15, 2011
  1. @peff @gitster

    filter-branch: use require_clean_work_tree

    peff committed with gitster
    Filter-branch already requires that we have a clean work
    tree before starting. However, it failed to refresh the
    index before checking, which means it could be wrong in the
    case of stat-dirtiness.
    Instead of simply adding a call to refresh the index, let's
    switch to using the require_clean_work_tree function
    provided by git-sh-setup. It does exactly what we want, and
    with fewer lines of code and more specific output messages.
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Commits on May 14, 2008
  1. @peff @gitster

    filter-branch: fix variable export logic

    peff committed with gitster
    filter-branch tries to restore "old" copies of some
    environment variables by using the construct:
      unset var
      test -z "$old_var" || var="$old_var" && export var
    This is just wrong.  AND-list and OR-list operators && and || have equal
    precedence and they bind left to right.  The second term, var="$old"
    assignment always succeeds, so we always end up exporting var.
    On bash and dash, exporting an unset variable has no effect. However, on
    some shells (such as FreeBSD's /bin/sh), the shell exports the empty
    This manifested itself in this case as git-filter-branch setting
    GIT_INDEX_FILE to the empty string, which in turn caused its call to
    git-read-tree to fail, leaving the working tree pointing at the original
    HEAD instead of the rewritten one.
    To fix this, we change the short-circuit logic to better match the intent:
      test -z "$old_var" || {
        var="$old_var" && export var
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Commits on Mar 13, 2008
  1. @peff @gitster

    filter-branch: use $SHELL_PATH instead of 'sh'

    peff committed with gitster
    On some systems, 'sh' isn't very friendly. In particular,
    t7003 fails on Solaris because it doesn't understand $().
    Instead, use the specified SHELL_PATH to run shell code.
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
  2. @peff @gitster

    filter-branch: don't use xargs -0

    peff committed with gitster
    Some versions of xargs don't understand "-0"; fortunately in
    this case we can get the same effect by using "git clean".
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
  3. @peff @gitster

    tr portability fixes

    peff committed with gitster
    Specifying character ranges in tr differs between System V
    and POSIX. In System V, brackets are required (e.g.,
    '[A-Z]'), whereas in POSIX they are not.
    We can mostly get around this by just using the bracket form
    for both sets, as in:
      tr '[A-Z] '[a-z]'
    in which case POSIX interpets this as "'[' becomes '['",
    which is OK.
    However, this doesn't work with multiple sequences, like:
      # rot13
      tr '[A-Z][a-z]' '[N-Z][A-M][n-z][a-m]'
    where the POSIX version does not behave the same as the
    System V version. In this case, we must simply enumerate the
    This patch fixes problematic uses of tr in git scripts and
    test scripts in one of three ways:
      - if a single sequence, make sure it uses brackets
      - if multiple sequences, enumerate
      - if extra brackets (e.g., tr '[A]' 'a'), eliminate
    Signed-off-by: Jeff King <>
    Signed-off-by: Junio C Hamano <>
Something went wrong with that request. Please try again.