You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/03/09 10:32:18 UTC

[GitHub] nigjo commented on a change in pull request #443: [NETBEANS-451] search for git revision instead of mercurial one.

nigjo commented on a change in pull request #443: [NETBEANS-451] search for git revision instead of mercurial one.
URL: https://github.com/apache/incubator-netbeans/pull/443#discussion_r173415512
 
 

 ##########
 File path: nbbuild/antsrc/org/netbeans/nbbuild/HgId.java
 ##########
 @@ -53,33 +56,43 @@ public void setProperty(String property) {
         this.property = property;
     }
 
-    public @Override void execute() throws BuildException {
+    @Override
+    public void execute() throws BuildException {
         if (file == null || property == null) {
             throw new BuildException("define file and property");
         }
-        File dirstate = null;
-        for (File root = file; root != null; root = root.getParentFile()) {
-            File ds = new File(new File(root, ".hg"), "dirstate");
-            if (ds.isFile()) {
-                dirstate = ds;
+        Path headroot = null;
+        for (Path root = file.toPath(); root != null; root = root.getParent()) {
+            Path headpath = root.resolve(".git/HEAD");
+            if (Files.isRegularFile(headpath)) {
+                headroot = headpath;
                 break;
             }
         }
         String id = "unknown-revn";
-        if (dirstate != null && dirstate.length() >= 6) {
-            try {
-                try (InputStream is = new FileInputStream(dirstate)) {
-                    byte[] data = new byte[6];
-                    if (is.read(data) < 6) {
-                        throw new IOException("truncated read");
+        try {
+            if (headroot != null && Files.size(headroot) > 0l) {
+                List<String> lines = Files.readAllLines(headroot);
+                String line = lines.get(0);
+                String revLink = line.substring(line.indexOf(':')+1).trim();
+
+                Path revPath = headroot.getParent().resolve(revLink);
+                if(Files.isRegularFile(revPath) && Files.size(revPath) > 0l) {
+                    List<String> revlines = Files.readAllLines(revPath);
+                    String revline = revlines.get(0);
+                    if(revline.length()>=12){
+                        id = revline.substring(0, 12);
+                    } else {
+                        log("no content in " + revPath, Project.MSG_WARN);                        
 
 Review comment:
   The git-commit ID is longer than 12 characters (see git docs). so the "revline" is always longer, but has to be at least 12 characters.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists