Coverage Report - com.aragost.javahg.commands.LogCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
LogCommand
100%
15/15
50%
1/2
1.2
 
 1  
 /*
 2  
  * #%L
 3  
  * JavaHg
 4  
  * %%
 5  
  * Copyright (C) 2011 aragost Trifork ag
 6  
  * %%
 7  
  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  
  * of this software and associated documentation files (the "Software"), to deal
 9  
  * in the Software without restriction, including without limitation the rights
 10  
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  
  * copies of the Software, and to permit persons to whom the Software is
 12  
  * furnished to do so, subject to the following conditions:
 13  
  * 
 14  
  * The above copyright notice and this permission notice shall be included in
 15  
  * all copies or substantial portions of the Software.
 16  
  * 
 17  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  
  * THE SOFTWARE.
 24  
  * #L%
 25  
  */
 26  
 package com.aragost.javahg.commands;
 27  
 
 28  
 import java.util.List;
 29  
 
 30  
 import com.aragost.javahg.Changeset;
 31  
 import com.aragost.javahg.Repository;
 32  
 import com.aragost.javahg.commands.flags.LogCommandFlags;
 33  
 import com.aragost.javahg.internals.HgInputStream;
 34  
 import com.aragost.javahg.internals.Utils;
 35  
 
 36  
 /**
 37  
  * Command class for executing <tt>hg log</tt>. Set flags from
 38  
  * {@link LogCommandFlags} and call the {@link #execute} method.
 39  
  */
 40  
 public class LogCommand extends LogCommandFlags {
 41  
 
 42  
     private String stylePath;
 43  4815
     private boolean eager = false;
 44  
   
 45  
     /**
 46  
      * @param repository
 47  
      *            the repository associated with this command.
 48  
      */
 49  
     public LogCommand(Repository repository) {
 50  4788
         this(repository, Changeset.CHANGESET_STYLE_PATH);
 51  4788
     }
 52  
 
 53  
     /**
 54  
      * Construct a LogCommand using the specified template.
 55  
      * 
 56  
      * @param repository
 57  
      * @param template
 58  
      */
 59  
     protected LogCommand(Repository repository, String stylePath) {
 60  4815
         super(repository);
 61  4815
         withDebugFlag();
 62  4815
         this.stylePath = stylePath;
 63  4815
     }
 64  
     
 65  
     /**
 66  
      * Enable eager load for changeset file data.
 67  
      * 
 68  
      * @return {@code this}
 69  
      */
 70  
     public LogCommand fileStatus(){
 71  1
       eager = true;
 72  1
       stylePath = Changeset.CHANGESET_EAGER_STYLE_PATH;
 73  1
       return this;
 74  
     }
 75  
 
 76  
     /**
 77  
      * @param files
 78  
      *            an optional list of files to retrieve the log for.
 79  
      *            With no files, all changesets are considered.
 80  
      * @return the log as a list of changesets
 81  
      */
 82  
     public List<Changeset> execute(String... files) {
 83  38
         if (stylePath != null) {
 84  38
             cmdAppend("--style", stylePath);
 85  
         }
 86  38
         HgInputStream stream = launchStream(files);
 87  37
         return Changeset.readListFromStream(getRepository(), stream, eager);
 88  
     }
 89  
 
 90  
     /**
 91  
      * Execute the log command and return a single Changeset.
 92  
      * <p>
 93  
      * If the log command gives more than one changeset an
 94  
      * {@link IllegalArgumentException} is thrown. <code>null</code>
 95  
      * is returned if the log command gives no Changesets.
 96  
      * 
 97  
      * @param files
 98  
      * @return a single Changeset
 99  
      * @throws IllegalArgumentException
 100  
      *             if the log command returns more than one changeset
 101  
      */
 102  
     public Changeset single(String... files) {
 103  4
         return Utils.single(execute(files));
 104  
     }
 105  
 
 106  
 }