From 9945034658585ea943e6326340c06b5932af8d67 Mon Sep 17 00:00:00 2001
Date: Thu, 5 Dec 2019 10:29:18 +0000
Subject: [PATCH] Support 'Git commit ID' in the SOURCE field of the release
 file.

Summary: <make>:Support 'Git commit ID' in the SOURCE field of the release file.
LLT: NA
Bug url: NA
---
 common/autoconf/spec.gmk.in |  1 +
 make/common/MakeBase.gmk    | 29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in
index 88f9f539..506cf617 100644
--- a/common/autoconf/spec.gmk.in
+++ b/common/autoconf/spec.gmk.in
@@ -578,6 +578,7 @@ READELF:=@READELF@
 EXPR:=@EXPR@
 FILE:=@FILE@
 HG:=@HG@
+GIT:=@GIT@
 OBJCOPY:=@OBJCOPY@
 SETFILE:=@SETFILE@
 XATTR:=@XATTR@
diff --git a/make/common/MakeBase.gmk b/make/common/MakeBase.gmk
index 9e5e704b..9b7ad702 100644
--- a/make/common/MakeBase.gmk
+++ b/make/common/MakeBase.gmk
@@ -308,18 +308,23 @@ REPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \
 
 # Emit the repo:id pairs to $@
 define GetSourceTips
-	$(CD) $(SRC_ROOT) ; \
-	for i in $(REPO_LIST) IGNORE ; do \
-	  if [ "$${i}" = "IGNORE" ] ; then \
-	    continue; \
-	  elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
-	    $(PRINTF) " %s:%s" \
-	        "$${i}" `$(HG) id -i --repository $${i}` ; \
-	  elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
-	    $(PRINTF) " %s:%s" \
-	        "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
-	  fi; \
-	done >> $@
+        $(if $(and $(HG), $(wildcard $(TOPDIR)/.hg)), \
+          $$($(CD) $(SRC_ROOT) ; \
+          for i in $(REPO_LIST) IGNORE ; do \
+            if [ "$${i}" = "IGNORE" ] ; then \
+              continue; \
+            elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
+              $(PRINTF) " %s:%s" \
+                  "$${i}" `$(HG) id -i --repository $${i}` ; \
+            elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
+              $(PRINTF) " %s:%s" \
+                  "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
+            fi; \
+          done >> $@), \
+          $(if $(and $(GIT), $(wildcard $(TOPDIR)/.git)), \
+            $(PRINTF) ".:git:%s%s\n" \
+                "$$(git log -n1 --format=%H | cut -c1-12)" \
+                "$$(if test -n "$$(git status --porcelain)"; then printf '+'; fi)" >> $@, ))
 	$(PRINTF) "\n" >> $@
 endef
 
-- 
2.19.0

