]> git.lizzy.rs Git - plan9front.git/commit
git: better handling of absolute paths, regex metachars
authorOri Bernstein <ori@eigenstate.org>
Tue, 17 Aug 2021 04:31:15 +0000 (04:31 +0000)
committerOri Bernstein <ori@eigenstate.org>
Tue, 17 Aug 2021 04:31:15 +0000 (04:31 +0000)
commitcfebf83947550f3ae730cef4a9b1ab6bf6b8d4f7
tree83ff1d02d9396579ef409eb91caefd2b96628e8d
parente524e8d65a7573c46d7beb49e77bfc2d55a5563d
git: better handling of absolute paths, regex metachars

Git currently gets a bit confused if you try to
manipulate files by absolute path.  There were also a
number of places where user-controlled file paths ended
up getting passed to regex interpretation, which could
confuse things.

This change mainly does 2 things:

- Adds a 'drop' function which drops
  a non-regex prefix from a string, and uses
  that to manipulate paths, simplifies 'subst',
  and removes 'subst -g', which was only used
  with fixed regexes; sed does this job fine.
- When getting a path from a user, we
  make it absolute and then strip out the head

Along the way it cleans up a couple of stupids:

- 'for(f in $list) if(! ~ $#f 0) use $f:
  $f can't be a nil list because of
  list flattening.
- removes a useless substitution here:

  all=`$nl{{git/query -c $1 $2; git/query -c $2 $3} | sed 's/^..//' | \
gsubst '^('$ourbr'|'$basebr'|'$theirbr')/*' | sort | uniq}

  where git/query -c doesn't produce
  paths prefixed with the query.
sys/lib/git/common.rc
sys/src/cmd/git/add
sys/src/cmd/git/clone
sys/src/cmd/git/merge
sys/src/cmd/git/pull
sys/src/cmd/git/revert