aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-28 15:33:31 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-28 15:33:31 +0000
commit472f830351a7a113cf72655daf29758aff9772bd (patch)
tree7d30af29939f46f5768ecae895913aec32e8ac9a /experimental
parent60a51219ef2fdddfe4855541bfd77138fd1c3b9d (diff)
Add git revision info to the titlebar
BUG=skia: R=mtklein@google.com Author: jcgregorio@google.com Review URL: https://codereview.chromium.org/258033006 git-svn-id: http://skia.googlecode.com/svn/trunk@14407 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r--experimental/webtry/css/webtry.css5
-rw-r--r--experimental/webtry/templates/index.html2
-rw-r--r--experimental/webtry/templates/recent.html2
-rw-r--r--experimental/webtry/templates/titlebar.html1
-rw-r--r--experimental/webtry/templates/workspace.html2
-rw-r--r--experimental/webtry/webtry.go46
6 files changed, 44 insertions, 14 deletions
diff --git a/experimental/webtry/css/webtry.css b/experimental/webtry/css/webtry.css
index 70a2c5e38e..dfcbb5372e 100644
--- a/experimental/webtry/css/webtry.css
+++ b/experimental/webtry/css/webtry.css
@@ -77,3 +77,8 @@ pre, code {
#tryHistory .tries {
float: none;
}
+
+#gitInfo {
+ float: right;
+ font-size: 70%;
+}
diff --git a/experimental/webtry/templates/index.html b/experimental/webtry/templates/index.html
index bab6c00545..96e9a205d1 100644
--- a/experimental/webtry/templates/index.html
+++ b/experimental/webtry/templates/index.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="/css/" type="text/css" media="screen">
</head>
<body>
- {{template "titlebar.html"}}
+ {{template "titlebar.html" .}}
{{template "content.html" .}}
<script type='text/javascript' charset='utf-8'>
diff --git a/experimental/webtry/templates/recent.html b/experimental/webtry/templates/recent.html
index 96be7141cd..de45ec6e1a 100644
--- a/experimental/webtry/templates/recent.html
+++ b/experimental/webtry/templates/recent.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="/css/" type="text/css" media="screen">
</head>
<body>
- {{template "titlebar.html"}}
+ {{template "titlebar.html" .}}
<section id=content>
<h1>Recent Activity</h1>
<section>
diff --git a/experimental/webtry/templates/titlebar.html b/experimental/webtry/templates/titlebar.html
index 93f64109af..0b7ef2d141 100644
--- a/experimental/webtry/templates/titlebar.html
+++ b/experimental/webtry/templates/titlebar.html
@@ -3,4 +3,5 @@
<a href="/recent/">Recent</a>
<a href="/w/">Workspace</a>
<a href="https://github.com/google/skia/tree/master/experimental/webtry">Code</a>
+ <a id=gitInfo href="https://github.com/google/skia/commit/{{.Titlebar.GitHash}}">{{.Titlebar.GitInfo}}</a>
</section>
diff --git a/experimental/webtry/templates/workspace.html b/experimental/webtry/templates/workspace.html
index 18b858f7e8..1be88ca92c 100644
--- a/experimental/webtry/templates/workspace.html
+++ b/experimental/webtry/templates/workspace.html
@@ -11,7 +11,7 @@
<img width=64 height=64 src="">
</div>
</template>
- {{template "titlebar.html"}}
+ {{template "titlebar.html" .}}
{{if .Name}}
{{template "content.html" .}}
diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go
index 6aa186ced8..573d9c67e8 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,18 @@ func init() {
panic(err)
}
+ // The git command returns output of the format:
+ //
+ // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000
+ //
+ logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`, true)
+ if err != nil {
+ panic(err)
+ }
+ logInfo := strings.Split(logOutput, " ")
+ gitHash = logInfo[0]
+ gitInfo = logInfo[1] + " " + logInfo[2] + " " + logInfo[0][0:6]
+
// 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 +236,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 +256,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.
@@ -356,7 +378,8 @@ type Try struct {
}
type Recent struct {
- Tries []Try
+ Tries []Try
+ Titlebar Titlebar
}
// recentHandler shows the last 20 tries.
@@ -379,16 +402,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.
@@ -448,7 +472,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" {
@@ -568,7 +592,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" {