Chromium Code Reviews| Index: experimental/webtry/webtry.go |
| diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go |
| index 8e02a751a32f6786f00cb669a837e02d01f9602a..403063efa8e32c13562207df57c593175efef1d4 100644 |
| --- a/experimental/webtry/webtry.go |
| +++ b/experimental/webtry/webtry.go |
| @@ -98,6 +98,9 @@ var ( |
| "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "paper", |
| "frog", "smoke", "star", |
| } |
| + |
| + gitHash = "" |
| + gitInfo = "" |
| ) |
| // flags |
| @@ -163,6 +166,21 @@ func init() { |
| panic(err) |
| } |
| + // The git command returns output of the format: |
| + // |
| + // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000 |
| + // M include/core/SkDynamicAnnotations.h |
|
mtklein
2014/04/28 15:06:20
Hey, I know this change...
|
| + // M include/core/SkOnce.h |
| + // M include/core/SkRefCnt.h |
| + // |
| + logOutput, err := doCmd(`git log --format=%H%x20%ai --name-status HEAD^..HEAD`, true) |
| + if err != nil { |
| + panic(err) |
| + } |
| + logInfo := strings.Split(logOutput, " ") |
| + gitHash = logInfo[0] |
| + gitInfo = logInfo[1] + " " + logInfo[2] + " " + logInfo[0][0:6] |
|
mtklein
2014/04/28 15:06:20
Looks like we just need the results of git log --f
jcgregorio
2014/04/28 15:11:57
Done.
|
| + |
| // Connect to MySQL server. First, get the password from the metadata server. |
| // See https://developers.google.com/compute/docs/metadata#custom. |
| req, err := http.NewRequest("GET", "http://metadata/computeMetadata/v1/instance/attributes/password", nil) |
| @@ -221,10 +239,17 @@ func init() { |
| } |
| } |
| +// Titlebar is used in titlebar template expansion. |
| +type Titlebar struct { |
| + GitHash string |
| + GitInfo string |
| +} |
| + |
| // userCode is used in template expansion. |
| type userCode struct { |
| - Code string |
| - Hash string |
| + Code string |
| + Hash string |
| + Titlebar Titlebar |
| } |
| // expandToFile expands the template and writes the result to the file. |
| @@ -234,7 +259,7 @@ func expandToFile(filename string, code string, t *template.Template) error { |
| return err |
| } |
| defer f.Close() |
| - return t.Execute(f, userCode{Code: code}) |
| + return t.Execute(f, userCode{Code: code, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}) |
| } |
| // expandCode expands the template into a file and calculate the MD5 hash. |
| @@ -365,7 +390,8 @@ type Try struct { |
| } |
| type Recent struct { |
| - Tries []Try |
| + Tries []Try |
| + Titlebar Titlebar |
| } |
| // recentHandler shows the last 20 tries. |
| @@ -388,16 +414,17 @@ func recentHandler(w http.ResponseWriter, r *http.Request) { |
| } |
| recent = append(recent, Try{Hash: hash, CreateTS: create_ts.Format("2006-02-01")}) |
| } |
| - if err := recentTemplate.Execute(w, Recent{Tries: recent}); err != nil { |
| + if err := recentTemplate.Execute(w, Recent{Tries: recent, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil { |
| log.Printf("ERROR: Failed to expand template: %q\n", err) |
| } |
| } |
| type Workspace struct { |
| - Name string |
| - Code string |
| - Hash string |
| - Tries []Try |
| + Name string |
| + Code string |
| + Hash string |
| + Tries []Try |
| + Titlebar Titlebar |
| } |
| // newWorkspace generates a new random workspace name and stores it in the database. |
| @@ -457,7 +484,7 @@ func workspaceHandler(w http.ResponseWriter, r *http.Request) { |
| hash = tries[len(tries)-1].Hash |
| code, _ = getCode(hash) |
| } |
| - if err := workspaceTemplate.Execute(w, Workspace{Tries: tries, Code: code, Name: name, Hash: hash}); err != nil { |
| + if err := workspaceTemplate.Execute(w, Workspace{Tries: tries, Code: code, Name: name, Hash: hash, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil { |
| log.Printf("ERROR: Failed to expand template: %q\n", err) |
| } |
| } else if r.Method == "POST" { |
| @@ -577,7 +604,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| // Expand the template. |
| - if err := indexTemplate.Execute(w, userCode{Code: code, Hash: hash}); err != nil { |
| + if err := indexTemplate.Execute(w, userCode{Code: code, Hash: hash, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil { |
| log.Printf("ERROR: Failed to expand template: %q\n", err) |
| } |
| } else if r.Method == "POST" { |