Commits

Jens Alfke committed fdc0323

Don't make assumptions about the order that "hg log" returns revisions in. (It's different if you specify --rev mm:nn). This fixes an exception after pulling.

Comments (0)

Files changed (1)

Source/HgLogOperation.m

 
 
 - (void) _updateRevision: (HgRevision*)revision
-                numbered: (int)revNo
            fromChangeset: (NSXMLElement*)changeset
 {
     if (_mode == kHgLogModeFull) {
     }
     
     // Link to its parent(s):
-    if( revNo > 0 ) {
+    if( revision.localNumber > 0 ) {
         NSArray *parents = stringsForXPath(changeset,@"parent/@rev");
         int parent;
         if( parents.count > 0 ) {
                 revision.parent2 = [self _revisionWithNumber: parent2];
             }
         } else
-            parent = revNo-1;
+            parent = revision.localNumber-1;
         
         revision.parent = [self _revisionWithNumber: parent];
     }
     if( ! changesets )
         return [self makeError: @"HgLogOperation couldn't get changesets from XML: %@",error];
     
+    // Build the _revisions array from the XML changeset info:
     _revisions = [NSMutableArray array];
     _revsByNumber = [NSMutableDictionary dictionary];
-    
-    // Go through changesets in reverse order (forward chronologically):
-    int n = changesets.count;
-    for( int i=n-1; i>=0; i-- ) {
-        NSXMLElement *changeset = [changesets objectAtIndex: i];
+    for (NSXMLElement *changeset in changesets) {
         int revNo = [[[changeset attributeForName: @"rev"] stringValue] intValue];
         HgRevisionID nodeID;
         if( ! identifierFromAttribute(changeset,@"node",&nodeID) )
             return [self makeError: @"HgLogOperation couldn't get changeset ID for rev #%i",revNo];
         HgRevision *revision = [_repository revisionWithID: nodeID];
-        if( revision ) {
-            [self _updateRevision: revision numbered: revNo fromChangeset: changeset];
-        } else {
+        if( !revision ) {
             revision = [[HgRevision alloc] initWithRepository: _repository
                                                   localNumber: revNo
                                                    identifier: nodeID];
-            [self _updateRevision: revision numbered: revNo fromChangeset: changeset];
-            [_revisions addObject: revision];
-            [_revsByNumber setObject: revision forKey: [NSNumber numberWithInt: revNo]];
         }
-        //Log(@"    Added revision #%i",revNo);
+        [_revisions addObject: revision];
+        [_revsByNumber setObject: revision forKey: [NSNumber numberWithInt: revNo]];
     }
+    
+    // Now update the revisions' attributes (and parent links) from the XML:
+    int i = 0;
+    for (NSXMLElement *changeset in changesets) {
+        HgRevision *revision = [_revisions objectAtIndex: i++];
+        [self _updateRevision: revision fromChangeset: changeset];
+    }
+    
+    // Sort revisions by increasing local rev number:
+    [_revisions sortUsingSelector: @selector(compare:)];
     return YES;
 }