-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feature. Quick View: Show history of file #573
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// QuickViewModel.h | ||
// Application | ||
// | ||
// Created by Dmitry Lobanov on 15/09/2019. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@import GitUpKit; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface QuickViewModel : NSObject | ||
- (instancetype)initWithRepository:(GCLiveRepository *)repository; | ||
|
||
// Checking | ||
@property (assign, nonatomic, readonly) BOOL hasPrevious; | ||
@property (assign, nonatomic, readonly) BOOL hasNext; | ||
@property (assign, nonatomic, readonly) BOOL hasPaging; | ||
|
||
// Moving | ||
- (void)moveBackward; | ||
- (void)moveForward; | ||
|
||
// States | ||
- (void)enterWithHistoryCommit:(GCHistoryCommit *)commit commitList:(NSArray *)commitList onResult:(void(^)(GCHistoryCommit *, NSArray * _Nullable))result; | ||
- (void)exit; | ||
@property (strong, nonatomic, readonly) GCHistoryCommit *currentCommit; | ||
@property (strong, nonatomic, readwrite) GCHistoryCommit *selectedCommit; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// QuickViewModel.m | ||
// Application | ||
// | ||
// Created by Dmitry Lobanov on 15/09/2019. | ||
// | ||
|
||
@import GitUpKit; | ||
#import <GitUpKit/XLFacilityMacros.h> | ||
#import "QuickViewModel.h" | ||
|
||
@interface QuickViewModel () | ||
|
||
@property (weak, nonatomic) GCLiveRepository *repository; | ||
|
||
@property (assign, nonatomic) NSUInteger index; | ||
@property (strong, nonatomic) NSMutableArray *commits; | ||
|
||
@property (strong, nonatomic) GCHistoryWalker *ancestors; | ||
@property (strong, nonatomic) GCHistoryWalker *descendants; | ||
|
||
#pragma mark - Protected | ||
- (void)loadMoreAncestors; | ||
- (void)loadMoreDescendants; | ||
@end | ||
|
||
@implementation QuickViewModel | ||
|
||
#pragma mark - Initialization | ||
- (instancetype)initWithRepository:(GCLiveRepository *)repository { | ||
if ((self = [super init])) { | ||
self.repository = repository; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - Loading | ||
- (void)loadMoreAncestors { | ||
if (![_ancestors iterateWithCommitBlock:^(GCHistoryCommit* commit, BOOL* stop) { | ||
[_commits addObject:commit]; | ||
}]) { | ||
_ancestors = nil; | ||
} | ||
} | ||
|
||
- (void)loadMoreDescendants { | ||
if (![_descendants iterateWithCommitBlock:^(GCHistoryCommit* commit, BOOL* stop) { | ||
[_commits insertObject:commit atIndex:0]; | ||
_index += 1; // We insert commits before the index too! | ||
}]) { | ||
_descendants = nil; | ||
} | ||
} | ||
|
||
#pragma mark - Checking | ||
- (BOOL)hasPrevious { | ||
return _index + 1 < _commits.count; | ||
} | ||
|
||
- (BOOL)hasNext { | ||
return _index > 0; | ||
} | ||
|
||
- (BOOL)hasPaging { | ||
return _commits != nil; | ||
} | ||
|
||
// TODO: Rename them appropriately. | ||
// Blowing mind. | ||
// Moving backward means moving to the end of array. ( or back to origin ) | ||
// Moving forward means moving to the beginning of array. ( or to recent commits ) | ||
// Also, these checks for end of array should be done __after__ increment or decrement of index. | ||
#pragma mark - Moving | ||
- (void)moveBackward { | ||
_index += 1; | ||
if (_index == _commits.count - 1) { | ||
[self loadMoreAncestors]; | ||
} | ||
} | ||
|
||
- (void)moveForward { | ||
_index -= 1; | ||
if (_index == 0) { | ||
[self loadMoreDescendants]; | ||
} | ||
} | ||
|
||
#pragma mark - State | ||
- (void)enterWithHistoryCommit:(GCHistoryCommit *)commit commitList:(NSArray *)commitList onResult:(void(^)(GCHistoryCommit *, NSArray * _Nullable))result { | ||
|
||
// actually, we need to cleanup state if we reenter this function. | ||
[self exit]; | ||
|
||
[_repository suspendHistoryUpdates]; // We don't want the the history to change while in QuickView because of the walkers | ||
|
||
_commits = [NSMutableArray new]; | ||
if (commitList) { | ||
[_commits addObjectsFromArray:commitList]; | ||
_index = [_commits indexOfObjectIdenticalTo:commit]; | ||
if (result) { | ||
result(commit, commitList); | ||
} | ||
XLOG_DEBUG_CHECK(_index != NSNotFound); | ||
} | ||
else { | ||
[_commits addObject:commit]; | ||
_index = 0; | ||
_ancestors = [_repository.history walkerForAncestorsOfCommits:@[ commit ]]; | ||
[self loadMoreAncestors]; | ||
_descendants = [_repository.history walkerForDescendantsOfCommits:@[ commit ]]; | ||
[self loadMoreDescendants]; | ||
if (result) { | ||
result(commit, nil); | ||
} | ||
} | ||
} | ||
|
||
- (void)cleanup { | ||
_commits = nil; | ||
_ancestors = nil; | ||
_descendants = nil; | ||
} | ||
|
||
- (void)exit { | ||
[self cleanup]; | ||
// resume history updates for repository. | ||
if ([_repository areHistoryUpdatesSuspended]) { | ||
[_repository resumeHistoryUpdates]; | ||
} | ||
} | ||
|
||
- (GCHistoryCommit *)currentCommit { | ||
return _commits[_index]; | ||
} | ||
|
||
- (void)setSelectedCommit:(GCHistoryCommit *)selectedCommit { | ||
NSUInteger index = [_commits indexOfObjectIdenticalTo:selectedCommit]; | ||
if (index == NSNotFound) { | ||
// set index to zero. | ||
_index = 0; | ||
} | ||
else { | ||
_index = index; | ||
} | ||
} | ||
|
||
- (GCHistoryCommit *)selectedCommit { | ||
return self.currentCommit; | ||
} | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an actual TODO?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I added a note about it.
If we move backward, then, we should increase index. (And load Ancestors)
If we move forward, then, we should decrease index. (And load Descendants)
If these statements are logically correct, then, we could keep current API.
Otherwise, we need to rethink it.