Skip to content

Commit

Permalink
Speed up zaw-src-git-files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenbeese committed Aug 27, 2012
1 parent 0425ea7 commit 65b8cc5
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions sources/git-files.zsh
@@ -1,38 +1,25 @@
# zaw source for git files

function zaw-src-git-files() {
local modifies unsorted_candidates
integer i j k cand_l modi_l
local all_files modified raw_candidates raw_cand_descriptions
local all_without_modified mod_description
git rev-parse --git-dir >/dev/null 2>&1
if [[ $? == 0 ]]; then
: ${(A)unsorted_candidates::=${(f)"$(git ls-files $(git rev-parse --show-cdup))"}}
: ${(A)modifies::=${(f)"$(git ls-files $(git rev-parse --show-cdup) --modified)"}}
cand_l=${#unsorted_candidates}
modi_l=${#modifies}
if [[ "$modifies[$modi_l]" != "" ]]; then
for i in {1..$modi_l}; do
candidates[$i]="${modifies[$i]}"
cand_descriptions[$i]="${modifies[$i]} MODIFIED"
done
k=`expr "$modi_l" + 1`
all_files=$(git ls-files $(git rev-parse --show-cdup))
modified=$(git ls-files $(git rev-parse --show-cdup) --modified)
if [[ $modified == "" ]]; then
raw_candidates=$all_files
raw_cand_descriptions=$all_files
else
k=1
mod_description=$(echo $modified | awk '{print $0 " MODIFIED"}')
all_without_modified=$(echo "${modified}\\n${all_files}" |sort |uniq -u )
raw_candidates=$(echo "${modified}\\n${all_without_modified}")
raw_cand_descriptions=$(echo "${mod_description}\\n${all_without_modified}")
fi
# This dual loop may be somewhat heavy.
for i in {1..$cand_l}; do
for j in {1..$modi_l}; do
if [[ "${modifies[$j]}" == "${unsorted_candidates[$i]}" ]]; then
break
fi
if [[ "$j" == "$modi_l" ]]; then
candidates[$k]="${unsorted_candidates[$i]}"
cand_descriptions[$k]="${unsorted_candidates[$i]}"
k=`expr "$k" + 1`
fi
done
done
fi
: ${(A)candidates::=${(f)"$(echo $raw_candidates)"}}
: ${(A)cand_descriptions::=${(f)"$(echo $raw_cand_descriptions)"}}

fi

actions=("zaw-callback-edit-file" "zaw-src-git-files-add" "zaw-callback-append-to-buffer")
act_descriptions=("edit file" "add" "append to edit buffer")
Expand Down

0 comments on commit 65b8cc5

Please sign in to comment.