]> source.dussan.org Git - jgit.git/commitdiff
Unwind loop that iterates over fetch connection refs. 56/4056/1
authorKevin Sawicki <kevin@github.com>
Mon, 22 Aug 2011 20:10:31 +0000 (13:10 -0700)
committerKevin Sawicki <kevin@github.com>
Mon, 22 Aug 2011 20:10:31 +0000 (13:10 -0700)
Create separate loops based on whether the ref specs
collection is empty or not.

Change-Id: I2861b45fe083675e12ff47f591e104f8cf6dd216
Signed-off-by: Kevin Sawicki <kevin@github.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java

index 9d036e24f0b5b168e166e7bded07d756d453980c..093d6cc1b2774cef7003c6c51b7ce0a7ed81e79c 100644 (file)
@@ -73,7 +73,9 @@ public class LsRemoteCommand extends GitCommand<Collection<Ref>> {
        private String remote = Constants.DEFAULT_REMOTE_NAME;
 
        private boolean heads;
+
        private boolean tags;
+
        private String uploadPack;
 
        /**
@@ -118,7 +120,7 @@ public class LsRemoteCommand extends GitCommand<Collection<Ref>> {
 
        /**
         * The full path of git-upload-pack on the remote host
-        * 
+        *
         * @param uploadPack
         */
        public void setUploadPack(String uploadPack) {
@@ -134,32 +136,27 @@ public class LsRemoteCommand extends GitCommand<Collection<Ref>> {
 
                        try {
                                Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1);
-                               if (tags) {
+                               if (tags)
                                        refSpecs.add(new RefSpec(
                                                        "refs/tags/*:refs/remotes/origin/tags/*"));
-                               }
-                               if (heads) {
+                               if (heads)
                                        refSpecs.add(new RefSpec(
                                                        "refs/heads/*:refs/remotes/origin/*"));
-                               }
                                Collection<Ref> refs;
                                Map<String, Ref> refmap = new HashMap<String, Ref>();
                                FetchConnection fc = transport.openFetch();
                                try {
                                        refs = fc.getRefs();
-                                       for (Ref r : refs) {
-                                               boolean found = refSpecs.isEmpty();
-                                               for (RefSpec rs : refSpecs) {
-                                                       if (rs.matchSource(r)) {
-                                                               found = true;
-                                                               break;
-                                                       }
-                                               }
-                                               if (found) {
+                                       if (refSpecs.isEmpty())
+                                               for (Ref r : refs)
                                                        refmap.put(r.getName(), r);
-                                               }
-
-                                       }
+                                       else
+                                               for (Ref r : refs)
+                                                       for (RefSpec rs : refSpecs)
+                                                               if (rs.matchSource(r)) {
+                                                                       refmap.put(r.getName(), r);
+                                                                       break;
+                                                               }
                                } finally {
                                        fc.close();
                                }