Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untracked only status view #909

Merged
merged 3 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions include/tig/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ bool status_stage_info_(char *buf, size_t bufsize,
status_stage_info_(buf, sizeof(buf), type, status)
extern struct view status_view;

static inline void
open_status_view(struct view *prev, enum open_flags flags)
{
open_view(prev, &status_view, flags);
}
void open_status_view(struct view *prev, bool untracked_only, enum open_flags flags);

#endif
/* vim: set ts=8 sw=8 noexpandtab: */
7 changes: 3 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,9 @@ main_request(struct view *view, enum request request, struct line *line)
if (line->type == LINE_STAT_UNSTAGED
|| line->type == LINE_STAT_STAGED)
open_stage_view(view, NULL, line->type, flags);
else if (line->type == LINE_STAT_UNTRACKED) {
open_status_view(view, flags);
status_exists(&status_view, NULL, LINE_STAT_UNTRACKED);
} else
else if (line->type == LINE_STAT_UNTRACKED)
open_status_view(view, true, flags);
else
open_diff_view(view, flags);
break;

Expand Down
1 change: 1 addition & 0 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ stage_open(struct view *view, enum open_flags flags)
break;

case LINE_STAT_UNTRACKED:
watch_register(&view->watch, WATCH_INDEX_UNTRACKED);
argv = file_argv;
view->encoding = get_path_encoding(stage_status.old.name, default_encoding);
break;
Expand Down
23 changes: 21 additions & 2 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@
#include "tig/git.h"
#include "tig/watch.h"
#include "tig/status.h"
#include "tig/main.h"
#include "tig/stage.h"

/*
* Status backend
*/

static char status_onbranch[SIZEOF_STR];
static bool show_untracked_only = false;

void
open_status_view(struct view *prev, bool untracked_only, enum open_flags flags)
{
if (show_untracked_only != untracked_only) {
show_untracked_only = untracked_only;
flags |= OPEN_RELOAD;
}
open_view(prev, &status_view, flags);
}

/* This should work even for the "On branch" line. */
static inline bool
Expand Down Expand Up @@ -148,11 +160,15 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
watch_apply(&view->watch, WATCH_INDEX_STAGED_NO);
else if (type == LINE_STAT_UNSTAGED)
watch_apply(&view->watch, WATCH_INDEX_UNSTAGED_NO);
else if (type == LINE_STAT_UNTRACKED)
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_NO);
} else {
if (type == LINE_STAT_STAGED)
watch_apply(&view->watch, WATCH_INDEX_STAGED_YES);
else if (type == LINE_STAT_UNSTAGED)
watch_apply(&view->watch, WATCH_INDEX_UNSTAGED_YES);
else if (type == LINE_STAT_UNTRACKED)
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_YES);
}

io_done(&io);
Expand Down Expand Up @@ -370,8 +386,8 @@ status_open(struct view *view, enum open_flags flags)

update_index();

if (!status_run(view, staged_argv, staged_status, LINE_STAT_STAGED) ||
!status_run(view, status_diff_files_argv, 0, LINE_STAT_UNSTAGED) ||
if ((!show_untracked_only && !status_run(view, staged_argv, staged_status, LINE_STAT_STAGED)) ||
(!show_untracked_only && !status_run(view, status_diff_files_argv, 0, LINE_STAT_UNSTAGED)) ||
!status_read_untracked(view))
return error("Failed to load status data");

Expand Down Expand Up @@ -738,6 +754,9 @@ status_request(struct view *view, enum request request, struct line *line)
return request;
}

if (show_untracked_only && view->parent == &main_view && !main_status_exists(view->parent, LINE_STAT_UNTRACKED))
return REQ_VIEW_CLOSE;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if the status can only ever have the main view as the parent it would still be good to have a view->parent == &main_view before calling main_status_exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wilco

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like "Impossible Germany" :-)
https://www.youtube.com/watch?v=r_0BPqWpM_M


refresh_view(view);

return REQ_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ view_driver(struct view *view, enum request request)
open_blob_view(view, OPEN_DEFAULT);
break;
case REQ_VIEW_STATUS:
open_status_view(view, OPEN_DEFAULT);
open_status_view(view, false, OPEN_DEFAULT);
break;
case REQ_VIEW_STAGE:
open_stage_view(view, NULL, 0, OPEN_DEFAULT);
Expand Down
9 changes: 8 additions & 1 deletion src/watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ watch_index_handler(struct watch_handler *handler, enum watch_event event, enum

if (!check_file_mtime(&handler->last_modified, "%s/index", repo.git_dir) ||
event == WATCH_EVENT_SWITCH_VIEW ||
!index_diff(&diff, false, false))
!index_diff(&diff, opt_show_untracked, false))
return WATCH_NONE;

if (check & WATCH_INDEX_STAGED) {
Expand All @@ -129,6 +129,13 @@ watch_index_handler(struct watch_handler *handler, enum watch_event event, enum
changed |= WATCH_INDEX_UNSTAGED_NO;
}

if (check & WATCH_INDEX_UNTRACKED) {
if (diff.untracked)
changed |= WATCH_INDEX_UNTRACKED_YES;
else
changed |= WATCH_INDEX_UNTRACKED_NO;
}

if (changed)
handler->last_modified = time(NULL);

Expand Down
16 changes: 8 additions & 8 deletions test/main/untracked-test
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ $YYY_MM_DD_HH_MM +0000 Unknown o Staged changes

[main] Untracked changes 100%
On branch master
Changes to be committed:
M .j
Changes not staged for commit:
M a
M b.c
M e/f
M g h
Untracked files:
? z

[status] Press u to stage all files for addition 100%







[status] Nothing to update 100%
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet

EOF