/*******************************************************************************
 * Copyright (c) 2004, 2006 svnClientAdapter project and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     svnClientAdapter project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.svnclientadapter.javahl;

import java.util.Date;

import org.tigris.subversion.javahl.BlameCallback;
import org.tigris.subversion.javahl.BlameCallback2;
import org.tigris.subversion.svnclientadapter.Annotations;

/**
 * JavaHL specific subclass of {@link Annotations}.
 * It implements a {@link org.tigris.subversion.javahl.BlameCallback}
 * as means of constructing the annotation records.  
 * 
 */
public class JhlAnnotations extends Annotations implements BlameCallback, BlameCallback2 {
	
    /* (non-Javadoc)
     * @see org.tigris.subversion.javahl.BlameCallback#singleLine(java.util.Date, long, java.lang.String, java.lang.String)
     */
    public void singleLine(Date changed, long revision, String author,
                           String line) {
    	addAnnotation(new Annotation(revision, author, changed, line));
    }

	public void singleLine(Date changed, long revision, String author,
			Date merged_date, long merged_revision, String merged_author,
			String mergedPath, String line) {
	   	addAnnotation(new Annotation(getRevision(revision, merged_revision), getAuthor(author, merged_author), getDate(changed, merged_date), line));
	}
	
	private long getRevision(long revision, long merged_revision) {
		if (merged_revision == -1)
			return revision;
		else
			return merged_revision;
	}
	
	private String getAuthor(String author, String merged_author) {
		if (merged_author == null)
			return author;
		else
			return merged_author;
	}
	
	private Date getDate(Date changed, Date merged_date) {
		if (merged_date == null)
			return changed;
		else
			return merged_date;
	}
}

@@ -1915,61 +1915,46 @@
  %7B%0A%09
-   %09addAnnotation(new Annotation(getRevision(
+%09if (merged_revision == -1 %7C%7C 
 revision
 , me
@@ -1949,17 +1949,19 @@
 revision
-,
+ %3C=
  merged_
@@ -1973,523 +1973,171 @@
 ion)
-, getAuthor(author, merged_author), getDate(changed, merged_date), line));%0A%09%7D%0A%09%0A%09private long getRevision(long revision, long merged_revision) %7B%0A%09%09if (merged_revision == -1)%0A%09%09%09return revision;%0A%09%09else%0A%09%09%09return merged_revision;%0A%09%7D%0A%09%0A%09private String getAuthor(String author, String merged_author) %7B%0A%09%09if (merged_author == null)%0A%09%09%09return author;%0A%09%09else%0A%09%09%09return merged_author;%0A%09%7D%0A%09%0A%09private Date getDate(Date changed, Date merged_date) %7B%0A%09%09if (merged_date == null)%0A%09%09%09return changed;%0A%09%09else%0A%09%09%09return merged_date;
+%0A%09%09%09addAnnotation(new Annotation(revision, author, changed, line));%0A%09%09else%0A%09%09%09addAnnotation(new Annotation(merged_revision, merged_author, merged_date, line));%0A%09%7D
 %0A%09
-%7D
 %0A%7D%0A

Fix building of blame information when includeMergedRevisions = true.