]> source.dussan.org Git - jgit.git/commitdiff
Don't iterate over advertised refs when HEAD is null 81/4681/1
authorKevin Sawicki <kevin@github.com>
Sat, 26 Nov 2011 22:47:21 +0000 (14:47 -0800)
committerKevin Sawicki <kevin@github.com>
Sat, 26 Nov 2011 22:47:21 +0000 (14:47 -0800)
Moves the check from inside the loop to outside the loop
and returns immediately if the HEAD advertisded ref is null

Change-Id: I539da6cafb4f73610b8e00259e32bd4d57f4f4cc

org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

index 5c98e6a28d38ed79962b4eabfdb0801e4544fc93..dbc126e895a74e2f93f086534f8fd7bd05d484fa 100644 (file)
@@ -226,14 +226,14 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
        }
 
        private Ref findBranchToCheckout(FetchResult result) {
-               Ref foundBranch = null;
                final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
+               if (idHEAD == null)
+                       return null;
+               Ref foundBranch = null;
                for (final Ref r : result.getAdvertisedRefs()) {
                        final String n = r.getName();
                        if (!n.startsWith(Constants.R_HEADS))
                                continue;
-                       if (idHEAD == null)
-                               continue;
                        if (r.getObjectId().equals(idHEAD.getObjectId())) {
                                foundBranch = r;
                                break;