gitcmds: remove unused worktree_state() function

It was a simple wrapper around the worktree_state_dict() function, but it
was never used.  Remove it, and rename worktree_state_dict() to
worktree_state().

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: rename filter_paths variable to args

In the diff_index() function, the filter_paths variable held more than
just the paths (it held the <tree-ish> arg as well).  Rename all usages
to args for consistency.

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: handle submodules on empty branch

The diff_index() function has to be careful to handle the case
of a branch without any commits (e.g. immediately after a git init or a
git checkout --orphan).  In that case there is no HEAD commit to compare
against, which causes the git diff-index --cached HEAD call to fail.  In
that case the diff_index() function was simply returning the list of
tracked files.  However, if there were any submodules, they would not be
recognized as such and would be treated as normal files.  To address
this, if the initial git diff-index call fails, re-run it against the
SHA1 of the empty tree instead of against HEAD, and then continue with
the normal code path.

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: remove unneeded code in diff_worktree()

The diff_worktree() function had code to handle an error from the
git diff-files call, with a comment stating that it was for git init
(e.g. no commits yet).  However, that case does not actually cause an
error, because git diff-files compares the working tree with the index,
and the index always exists, even if there are no commits yet.  So,
remove the code for handling an error from git diff-files.

Signed-off-by: Daniel Harding <dharding@living180.net>
qtutils: inline create_treewidget_item()

This function had only a single caller and was simply a wrapper around
the TreeWidgetItem constructor, so inline its usage and remove the
function.

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: add function for parsing raw diff output

Add a utility function, _parse_raw_diff() which takes zero-delimited raw
diff output (e.g. from git diff-index) and returns a generator yielding
(path, status, is_submodule) tuples.  Update diff_index() and
diff_worktree() to use this function.

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: include submodules in path lists

Change diff_index() and diff_worktree() to include submodules in the
returned path lists, rather than adding them to the path lists in
worktree_state().  This simplifies the code and also avoids a bug where
an unmerged submodule would be displayed in the Staged section of the
Status widget instead of the Unmerged section.

Signed-off-by: Daniel Harding <dharding@living180.net>
gitcmds: simplify list updating logic

In the worktree_state() function, use simpler and more efficient logic
for removing unmerged paths from the modified list.

Signed-off-by: Daniel Harding <dharding@living180.net>
cmds: remove assignment to self.old_filename

The initializer for the Diff command was assigning self.old_filename,
which is unnecessary, because initializer of its parent class, Command,
performs that assignment already.  Remove the unnecessary assignment.

Signed-off-by: Daniel Harding <dharding@living180.net>
cmds: make certain commands take a single filename

The Diff, DiffStaged, and ShowUntracked commands took a list of
filenames when they were instantiated, but they each ignored all but the
first entry in the list.  Change them to just take a single filename
instead of a list, and update the callers appropriately.

Signed-off-by: Daniel Harding <dharding@living180.net>
models/main: track deleted files

git-cola was using the core.exists() function in several places to
determine whether or not a file had been deleted.  However, in certain
corner cases, this could result in incorrect behavior.  First, the
gitcmds.diff_helper() function only checked for the existence of a file
if the cached flag was True.  So, if a user ran rm <file> instead of
git rm <file>, the diff view would not have the "deleted file" header at
the top of the diff for the unstaged file.  Also, if the user ran
git rm <file> and then recreated the file (now untracked), the icon in
the Staged list would incorrectly change from the removed icon to the
staged icon.  Finally, if git-cola was used to amend a commit with
deleted files, they would be incorrectly displayed with the staged icon
instead of the removed icon.  Fix these problems by allowing the main
model to keep sets of staged and unstaged deleted files, and adapt
several places that used core.exists() function to consult the
appropriate set instead.

Signed-off-by: Daniel Harding <dharding@living180.net>
Merge pull request #394 from living180/file_status

status: submodule enhancements and refactoring

Signed-off-by: David Aguilar <davvid@gmail.com>