View Javadoc
1   /*
2    * Copyright (c) 2022 Airtango.
3    * All rights reserved.
4    */
5   
6   package de.funfried.netbeans.plugins.editor.closeleftright.extension.vcs.utils;
7   
8   import java.io.File;
9   
10  import org.netbeans.modules.mercurial.FileInformation;
11  import org.netbeans.modules.mercurial.Mercurial;
12  import org.openide.filesystems.FileObject;
13  import org.openide.filesystems.FileUtil;
14  
15  /**
16   *
17   * @author fbahle
18   */
19  public interface HgUtils {
20  	static Boolean isModified(FileObject fileObject) {
21  		int status = getStatus(fileObject);
22  		if (status == FileInformation.STATUS_UNKNOWN || status == FileInformation.STATUS_NOTVERSIONED_NOTMANAGED) {
23  			return null;
24  		}
25  
26  		return (status & FileInformation.STATUS_LOCAL_CHANGE) != 0;
27  	}
28  
29  	static int getStatus(FileObject fileObject) {
30  		if (fileObject != null) {
31  			File file = FileUtil.toFile(fileObject);
32  			if (file != null) {
33  				FileInformation fileInformation = Mercurial.getInstance().getFileStatusCache().getStatus(file);
34  				if (fileInformation != null) {
35  					return fileInformation.getStatus();
36  				}
37  			}
38  		}
39  
40  		return FileInformation.STATUS_UNKNOWN;
41  	}
42  }