Skip to content

Commit 7806e64

Browse files
David CatmullDavid Catmull
authored andcommitted
help tags for remotes now work
1 parent 1d24c1d commit 7806e64

8 files changed

+47
-15
lines changed

PBGitRepository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
127127
- (BOOL) hasRemotes;
128128
- (PBGitRef *) remoteRefForBranch:(PBGitRef *)branch error:(NSError **)error;
129129
- (NSString *) infoForRemote:(NSString *)remoteName;
130+
- (NSArray*) URLsForRemote:(NSString*)remoteName;
130131

131132
- (void) readCurrentBranch;
132133
- (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev;

PBGitRepository.m

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,32 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
278278
[refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
279279
}
280280

281-
// Extracts the text that should be shown in a help tag
281+
// Returns the remote's fetch and pull URLs as an array of two strings.
282+
- (NSArray*) URLsForRemote:(NSString*)remoteName
283+
{
284+
NSArray *arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", remoteName, nil];
285+
NSString *output = [self outputForArguments:arguments];
286+
287+
NSArray *remoteLines = [output componentsSeparatedByString:@"\n"];
288+
NSString *fetchURL = [remoteLines objectAtIndex:1];
289+
NSString *pushURL = [remoteLines objectAtIndex:2];
290+
291+
if ([fetchURL hasPrefix:@" Fetch URL: "] && [pushURL hasPrefix:@" Push URL: "])
292+
return [NSArray arrayWithObjects:
293+
[fetchURL substringFromIndex:13],
294+
[pushURL substringFromIndex:13],
295+
nil];
296+
return nil;
297+
}
298+
299+
// Extracts the text that should be shown in a help tag.
282300
- (NSString*) helpTextForRef:(PBGitRef*)ref
283301
{
284302
NSString *output = nil;
285303
NSString *name = [ref shortName];
286304
NSArray *arguments = nil;
287305

288-
if ([ref isRemote]) {
289-
arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", name, nil];
290-
output = [self outputForArguments:arguments];
291-
292-
NSArray *remoteLines = [output componentsSeparatedByString:@"\n"];
293-
294-
// Second and third lines have Fetch and Push URLs
295-
return [[remoteLines subarrayWithRange:NSMakeRange(1,1)] componentsJoinedByString:@"\n"];
296-
}
297-
else if ([ref isTag]) {
306+
if ([ref isTag]) {
298307
arguments = [NSArray arrayWithObjects:@"tag", @"-ln", name, nil];
299308
output = [self outputForArguments:arguments];
300309
if (![output hasPrefix:name])

PBGitSVRemoteItem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
@interface PBGitSVRemoteItem : PBSourceViewItem {
1414
BOOL alert;
15+
NSString *helpText;
1516
}
1617

1718
@property (assign) BOOL alert;
19+
@property (retain) NSString *helpText;
1820

1921
+ (id)remoteItemWithTitle:(NSString *)title;
2022

PBGitSVRemoteItem.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@implementation PBGitSVRemoteItem
1414

1515
@synthesize alert;
16+
@synthesize helpText;
1617

1718
+ (id)remoteItemWithTitle:(NSString *)title
1819
{

PBGitSidebarController.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
IBOutlet NSPopUpButton *actionButton;
2121
IBOutlet NSSegmentedControl *remoteControls;
2222

23-
IBOutlet NSButton* svnFetchButton;
24-
IBOutlet NSButton* svnRebaseButton;
25-
IBOutlet NSButton* svnDcommitButton;
23+
IBOutlet NSButton* svnFetchButton;
24+
IBOutlet NSButton* svnRebaseButton;
25+
IBOutlet NSButton* svnDcommitButton;
2626

2727
NSMutableArray *items;
2828

PBGitSidebarController.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe
344344

345345
- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
346346
{
347-
return [[item revSpecifier] helpText];
347+
return [item helpText];
348348
}
349349

350350
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
@@ -365,6 +365,17 @@ - (BOOL) outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(
365365
return ![item isUncollapsible];
366366
}
367367

368+
- (NSString*) helpTextForRemoteURLs:(NSArray*)urls
369+
{
370+
NSString *fetchURL = [urls objectAtIndex:0];
371+
NSString *pushURL = [urls objectAtIndex:1];
372+
373+
if ([fetchURL isEqual:pushURL])
374+
return fetchURL;
375+
else // Down triangle for fetch, up triangle for push
376+
return [NSString stringWithFormat:@"\u25bc %@\n\u25b2", fetchURL, pushURL];
377+
}
378+
368379
- (void)populateList
369380
{
370381
PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]];
@@ -384,6 +395,8 @@ - (void)populateList
384395

385396
for (PBGitRevSpecifier *rev in repository.branches)
386397
[self addRevSpec:rev];
398+
for (PBGitSVRemoteItem *remote in remotes.children)
399+
[remote setHelpText:[self helpTextForRemoteURLs:[[self repository] URLsForRemote:[remote title]]]];
387400

388401
[items addObject:project];
389402
[items addObject:branches];

PBSourceViewItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
+ (id)itemWithTitle:(NSString *)title;
3131

3232
- (NSString *)badge;
33+
- (NSString *)helpText;
3334

3435
- (void)addChild:(PBSourceViewItem *)child;
3536
- (void)removeChild:(PBSourceViewItem *)child;

PBSourceViewItem.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ - (NSString *)title
128128
return [[revSpecifier description] lastPathComponent];
129129
}
130130

131+
- (NSString *) helpText
132+
{
133+
return [revSpecifier helpText];
134+
}
135+
131136
- (NSString *) stringValue
132137
{
133138
return self.title;

0 commit comments

Comments
 (0)