Skip to content

Commit e00f734

Browse files
committed
Merge pull request brotherbard#61 from Uncommon/helptags
Help tags for remotes and tags
2 parents 96a8794 + 7806e64 commit e00f734

10 files changed

+70
-4
lines changed

PBGitRepository.h

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

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

PBGitRepository.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,41 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
292292
[refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
293293
}
294294

295+
// Returns the remote's fetch and pull URLs as an array of two strings.
296+
- (NSArray*) URLsForRemote:(NSString*)remoteName
297+
{
298+
NSArray *arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", remoteName, nil];
299+
NSString *output = [self outputForArguments:arguments];
300+
301+
NSArray *remoteLines = [output componentsSeparatedByString:@"\n"];
302+
NSString *fetchURL = [remoteLines objectAtIndex:1];
303+
NSString *pushURL = [remoteLines objectAtIndex:2];
304+
305+
if ([fetchURL hasPrefix:@" Fetch URL: "] && [pushURL hasPrefix:@" Push URL: "])
306+
return [NSArray arrayWithObjects:
307+
[fetchURL substringFromIndex:13],
308+
[pushURL substringFromIndex:13],
309+
nil];
310+
return nil;
311+
}
312+
313+
// Extracts the text that should be shown in a help tag.
314+
- (NSString*) helpTextForRef:(PBGitRef*)ref
315+
{
316+
NSString *output = nil;
317+
NSString *name = [ref shortName];
318+
NSArray *arguments = nil;
319+
320+
if ([ref isTag]) {
321+
arguments = [NSArray arrayWithObjects:@"tag", @"-ln", name, nil];
322+
output = [self outputForArguments:arguments];
323+
if (![output hasPrefix:name])
324+
return nil;
325+
return [[output substringFromIndex:[name length]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
326+
}
327+
return nil;
328+
}
329+
295330
- (void) reloadRefs
296331
{
297332
_headRef = nil;
@@ -321,6 +356,7 @@ - (void) reloadRefs
321356
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
322357
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
323358

359+
[revSpec setHelpText:[self helpTextForRef:newRef]];
324360
[self addBranch:revSpec];
325361
[self addRef:newRef fromParameters:components];
326362
[oldBranches removeObject:revSpec];

PBGitRevSpecifier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@interface PBGitRevSpecifier : NSObject <NSCopying> {
1313
NSString *description;
14+
NSString *helpText;
1415
NSArray *parameters;
1516
NSURL *workingDirectory;
1617
BOOL isSimpleRef;
@@ -36,6 +37,7 @@
3637
+ (PBGitRevSpecifier *)localBranchesRevSpec;
3738

3839
@property(retain) NSString *description;
40+
@property(retain) NSString *helpText;
3941
@property(readonly) NSArray *parameters;
4042
@property(retain) NSURL *workingDirectory;
4143
@property(readonly) BOOL isSimpleRef;

PBGitRevSpecifier.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@implementation PBGitRevSpecifier
1313

14-
@synthesize parameters, description, workingDirectory;
14+
@synthesize parameters, description, helpText, workingDirectory;
1515
@synthesize isSimpleRef;
1616
@synthesize behind,ahead;
1717

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe
342342
[cell setImage:[item icon]];
343343
}
344344

345+
- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
346+
{
347+
return [item helpText];
348+
}
349+
345350
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
346351
{
347352
return ![item isGroupItem];
@@ -360,6 +365,17 @@ - (BOOL) outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(
360365
return ![item isUncollapsible];
361366
}
362367

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+
363379
- (void)populateList
364380
{
365381
PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]];
@@ -379,6 +395,8 @@ - (void)populateList
379395

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

383401
[items addObject:project];
384402
[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)