[ARVADOS-DEV] updated: 87efaedde189534abe1276f2b6d810793449e4ce

Git user git at public.curoverse.com
Sun Sep 24 20:40:39 EDT 2017


Summary of changes:
 arvados-version-server/arvados-version-server.go      | 9 +++++++--
 arvados-version-server/arvados-version-server_test.go | 6 ++++--
 arvados-version-server/usage.go                       | 1 +
 3 files changed, 12 insertions(+), 4 deletions(-)

       via  87efaedde189534abe1276f2b6d810793449e4ce (commit)
      from  5299abea2be4525f91fb2947f2f7eef79ce0dc63 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 87efaedde189534abe1276f2b6d810793449e4ce
Author: Ward Vandewege <ward at curoverse.com>
Date:   Sun Sep 24 20:34:40 2017 -0400

    Make the short git hash length a configuration parameter, and default it
    to 7 (which is the historical default for our packages).
    
    For Debian Stretch, we're now using 9, but our pinning is done in such a
    way that the extra characters at the end of the package name are no
    problem.
    
    refs #
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <wvandewege at veritasgenetics.com>

diff --git a/arvados-version-server/arvados-version-server.go b/arvados-version-server/arvados-version-server.go
index f377979..f92dc31 100644
--- a/arvados-version-server/arvados-version-server.go
+++ b/arvados-version-server/arvados-version-server.go
@@ -62,6 +62,7 @@ type Config struct {
 	CacheDirPath      string
 	GitExecutablePath string
 	ListenPort        string
+	ShortHashLength   string
 
 	Packages []bundle
 }
@@ -423,7 +424,7 @@ func versionFromGit(prefix string) (string, error) {
 	if err != nil {
 		return "", err
 	}
-	cmdArgs := []string{"log", "-n1", "--first-parent", "--max-count=1", "--format=format:%h", "--abbrev=9", "."}
+	cmdArgs := []string{"log", "-n1", "--first-parent", "--max-count=1", "--format=format:%h", "--abbrev=" + theConfig.ShortHashLength, "."}
 	gitHash, err := exec.Command(theConfig.GitExecutablePath, cmdArgs...).Output()
 	if err != nil {
 		logError([]string{"There was an error running the command ", theConfig.GitExecutablePath, strings.Join(cmdArgs, " "), err.Error()})
@@ -709,7 +710,7 @@ func packageVersionHandler(w http.ResponseWriter, r *http.Request) {
 	hash := r.URL.Path[11:]
 
 	// Empty hash or non-standard hash length? Normalize it.
-	if len(hash) != 7 && len(hash) != 40 {
+	if string(len(hash)) != theConfig.ShortHashLength && len(hash) != 40 {
 		hash, err = normalizeRequestedHash(hash)
 		if err != nil {
 			m := report{"Error", err.Error()}
@@ -808,6 +809,10 @@ func main() {
 		theConfig.ListenPort = "80"
 	}
 
+	if theConfig.ShortHashLength == "" {
+		theConfig.ShortHashLength = "7"
+	}
+
 	http.HandleFunc("/v1/commit/", packageVersionHandler)
 	http.HandleFunc("/v1/about", aboutHandler)
 	http.HandleFunc("/v1/help", helpHandler)
diff --git a/arvados-version-server/arvados-version-server_test.go b/arvados-version-server/arvados-version-server_test.go
index 874c4b3..26e2824 100644
--- a/arvados-version-server/arvados-version-server_test.go
+++ b/arvados-version-server/arvados-version-server_test.go
@@ -49,13 +49,14 @@ func (s *ServerNotRequiredSuite) TestConfig(c *C) {
 	c.Check(config.CacheDirPath, Equals, "")
 	c.Check(config.GitExecutablePath, Equals, "")
 	c.Check(config.ListenPort, Equals, "")
+	c.Check(config.ShortHashLength, Equals, "")
 
 	// Test parsing of config data
 	tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
 	c.Check(err, IsNil)
 	defer os.Remove(tmpfile.Name())
 
-	argsS := `{"DirPath": "/x/y", "CacheDirPath": "/x/z", "GitExecutablePath": "/usr/local/bin/gitexecutable", "ListenPort": "12345"}`
+	argsS := `{"DirPath": "/x/y", "CacheDirPath": "/x/z", "GitExecutablePath": "/usr/local/bin/gitexecutable", "ListenPort": "12345", "ShortHashLength": "3"}`
 	_, err = tmpfile.Write([]byte(argsS))
 	c.Check(err, IsNil)
 
@@ -66,6 +67,7 @@ func (s *ServerNotRequiredSuite) TestConfig(c *C) {
 	c.Check(config.CacheDirPath, Equals, "/x/z")
 	c.Check(config.GitExecutablePath, Equals, "/usr/local/bin/gitexecutable")
 	c.Check(config.ListenPort, Equals, "12345")
+	c.Check(config.ShortHashLength, Equals, "3")
 
 }
 
@@ -83,7 +85,7 @@ func runServer(c *C) {
 
 	tmpConfigFileName = tmpfile.Name()
 
-	argsS := `{"DirPath": "", "CacheDirPath": "", "GitExecutablePath": "", "ListenPort": "12345"}`
+	argsS := `{"DirPath": "", "CacheDirPath": "", "GitExecutablePath": "", "ListenPort": "12345", "ShortHashLength": "9"}`
 	_, err = tmpfile.Write([]byte(argsS))
 	c.Check(err, IsNil)
 
diff --git a/arvados-version-server/usage.go b/arvados-version-server/usage.go
index b5ee85b..769b7b1 100644
--- a/arvados-version-server/usage.go
+++ b/arvados-version-server/usage.go
@@ -15,6 +15,7 @@ dirPath: "/tmp/arvados-version-server-checkout"
 cacheDirPath: "/tmp/arvados-version-server-cache"
 gitExecutablePath: "/usr/bin/git"
 listenPort: 8080
+shortHashLength: 7
 `)
 
 func usage(fs *flag.FlagSet) {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list