Skip to contentSkip to conversation

metadata_scm: use rev-parse rather than show-ref

PATCH In review Chris Larson 3 participants 3 messages Nov 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 metadata_scm: use rev-parse rather than show-ref

From: Chris Larson <[email protected]>

show-ref will show all matching refs, so a "show-ref HEAD" will show not just the local HEAD, but the fetched remote ones as well. This isn't what we want for this function, so change it to use rev-parse with --verify, and also change it to use --short, to shorten the hash to a more palatable length.

---
 classes/metadata_scm.bbclass |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
classes/metadata_scm.bbclass +13 -9
index ffc6a8a..f79ea19 100644
@@ -63,14 +63,18 @@ def base_get_metadata_svn_revision(path, d):
 	return revision
 
 def base_get_metadata_git_branch(path, d):
-	branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
-
-	if len(branch) != 0:
-		return branch.replace("refs/heads/", "")
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "symbolic-ref", "HEAD"], cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    else:
+        rev = rev.replace("refs/heads/", "")
+    return rev
 
 def base_get_metadata_git_revision(path, d):
-	rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
-	if len(rev) != 0:
-		return rev
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "rev-parse", "--verify", "--short", "HEAD"],
+                     cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    return rev
Signature · 1 line
1.7.2.3
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Chris Larson

From: Chris Larson<[email protected]>

show-ref will show all matching refs, so a "show-ref HEAD" will show not just the local HEAD, but the fetched remote ones as well. This isn't what we want for this function, so change it to use rev-parse with --verify, and also change it to use --short, to shorten the hash to a more palatable length.

---
  classes/metadata_scm.bbclass |   22 +++++++++++++---------
  1 files changed, 13 insertions(+), 9 deletions(-)
classes/metadata_scm.bbclass +7 -5
index ffc6a8a..f79ea19 100644
@@ -63,14 +63,18 @@ def base_get_metadata_svn_revision(path, d):
  	return revision
 
  def base_get_metadata_git_branch(path, d):
-	branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
-
-	if len(branch) != 0:
-		return branch.replace("refs/heads/", "")
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "symbolic-ref", "HEAD"], cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    else:
+        rev = rev.replace("refs/heads/", "")
+    return rev
 
  def base_get_metadata_git_revision(path, d):

classes/metadata_scm.bbclass def base_get_metadata_svn_revision(path, d): · line 80

Quoted 10 lines
classes/metadata_scm.bbclass +6 -4
-	rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
-	if len(rev) != 0:
-		return rev
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "rev-parse", "--verify", "--short", "HEAD"],
+                     cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    return rev

This resolves prior issues I had with revision mismatch

Acked-by on v1 1/1
#2 lore raw
In reply to Chris Larson
Quoted 8 lines · Chris Larson

From: Chris Larson <[email protected]>

show-ref will show all matching refs, so a "show-ref HEAD" will show not just the local HEAD, but the fetched remote ones as well. This isn't what we want for this function, so change it to use rev-parse with --verify, and also change it to use --short, to shorten the hash to a more palatable length.

seems to hold on my limited testing

Quoted 44 lines
---
 classes/metadata_scm.bbclass |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
classes/metadata_scm.bbclass +13 -9
index ffc6a8a..f79ea19 100644
@@ -63,14 +63,18 @@ def base_get_metadata_svn_revision(path, d):
 	return revision
 
 def base_get_metadata_git_branch(path, d):
-	branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
-
-	if len(branch) != 0:
-		return branch.replace("refs/heads/", "")
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "symbolic-ref", "HEAD"], cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    else:
+        rev = rev.replace("refs/heads/", "")
+    return rev
 
 def base_get_metadata_git_revision(path, d):
-	rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
-	if len(rev) != 0:
-		return rev
-	return "<unknown>"
+    try:
+        rev = oe_run(d, ["git", "rev-parse", "--verify", "--short", "HEAD"],
+                     cwd=path).rstrip()
+    except oe.process.CmdError:
+        rev = "<unknown>"
+    return rev
Signature · 7 lines
1.7.2.3


_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel