Skip to content

Commit e56ca10

Browse files
committed
Add search commands to the gitx cli
-s or --search= for searching in subject, author or SHA -S or --Search= for git's pickaxe string matching -r or --regex= for git's pickaxe regex matching
1 parent 71cdb0d commit e56ca10

12 files changed

+162
-2
lines changed

GitX.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- (void) delete; // Delete an object.
4444
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
4545
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
46+
- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.
4647

4748
@end
4849

@@ -66,6 +67,18 @@
6667
- (void) delete; // Delete an object.
6768
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
6869
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
70+
- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.
71+
72+
@end
73+
74+
75+
76+
/*
77+
* GitX Suite
78+
*/
79+
80+
// A document.
81+
@interface GitXDocument (GitXSuite)
6982

7083
@end
7184

GitX.sdef

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@
173173
</parameter>
174174
</command>
175175

176+
<command name="search" code="GitXSrch" description="Highlight commits that match the given search string.">
177+
<direct-parameter type="specifier" description="The repository document to search."/>
178+
<parameter name="string" code="SRCH" type="text" optional="yes" description="The string to search for.">
179+
<cocoa key="searchString"/>
180+
</parameter>
181+
<parameter name="in mode" code="Mode" type="integer" optional="yes" description="The type of search (defalts to basic [Subject, Author, SHA]).">
182+
<cocoa key="inMode"/>
183+
</parameter>
184+
</command>
185+
186+
<class-extension extends="document" code="docu" description="A document.">
187+
<cocoa class="PBGitRepository"/>
188+
<responds-to name="search">
189+
<cocoa method="findInModeScriptCommand:"/>
190+
</responds-to>
191+
</class-extension>
192+
176193
</suite>
177194

178195
</dictionary>

GitXScriptingConstants.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
#define kGitXAEKeyArgumentsList 'ARGS'
1313

1414
#define kGitXCloneDestinationURLKey @"destinationURL"
15-
#define kGitXCloneIsBareKey @"isBare"
15+
#define kGitXCloneIsBareKey @"isBare"
16+
17+
#define kGitXFindSearchStringKey @"searchString"
18+
#define kGitXFindInModeKey @"inMode"

PBGitRepository.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
125125
- (void) setup;
126126
- (void) forceUpdateRevisions;
127127

128+
// for the scripting bridge
129+
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
130+
131+
128132
@property (assign) BOOL hasChanged;
129133
@property (readonly) PBGitWindowController *windowController;
130134
@property (readonly) PBGitConfig *config;

PBGitRepository.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import "PBGitRevList.h"
2020
#import "PBGitDefaults.h"
2121
#import "GitXScriptingConstants.h"
22+
#import "PBHistorySearchController.h"
2223

2324
NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
2425

@@ -1008,6 +1009,19 @@ - (void)showWindows
10081009
[super showWindows];
10091010
}
10101011

1012+
// for the scripting bridge
1013+
- (void)findInModeScriptCommand:(NSScriptCommand *)command
1014+
{
1015+
NSDictionary *arguments = [command arguments];
1016+
NSString *searchString = [arguments objectForKey:kGitXFindSearchStringKey];
1017+
if (searchString) {
1018+
NSInteger mode = [[arguments objectForKey:kGitXFindInModeKey] integerValue];
1019+
[PBGitDefaults setShowStageView:NO];
1020+
[self.windowController showHistoryView:self];
1021+
[self.windowController setHistorySearch:searchString mode:mode];
1022+
}
1023+
}
1024+
10111025

10121026
#pragma mark low level
10131027

PBGitSidebarController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
- (IBAction) fetchPullPushAction:(id)sender;
4040

41+
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
42+
4143
@property(readonly) NSMutableArray *items;
4244
@property(readonly) NSView *sourceListControlsView;
4345
@end

PBGitSidebarController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "NSOutlineViewExt.h"
1616
#import "PBAddRemoteSheet.h"
1717
#import "PBGitDefaults.h"
18+
#import "PBHistorySearchController.h"
1819

1920
@interface PBGitSidebarController ()
2021

@@ -184,6 +185,11 @@ - (void) removeRevSpec:(PBGitRevSpecifier *)rev
184185
[sourceView reloadData];
185186
}
186187

188+
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
189+
{
190+
[historyViewController.searchController setHistorySearch:searchString mode:mode];
191+
}
192+
187193
#pragma mark NSOutlineView delegate methods
188194

189195
- (void)outlineViewSelectionDidChange:(NSNotification *)notification

PBGitWindowController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@
4747
- (IBAction) openInTerminal:(id)sender;
4848
- (IBAction) cloneTo:(id)sender;
4949
- (IBAction) refresh:(id)sender;
50+
51+
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
52+
5053
@end

PBGitWindowController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
191191
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
192192
}
193193

194+
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
195+
{
196+
[sidebarController setHistorySearch:searchString mode:mode];
197+
}
198+
194199

195200

196201
#pragma mark -

PBHistorySearchController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ typedef enum historySearchModes {
6060
- (void)clearSearch;
6161
- (IBAction)updateSearch:(id)sender;
6262

63+
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
64+
6365
@end

0 commit comments

Comments
 (0)