Merge lp:~niemeyer/lbox/long-summary into lp:lbox

Proposed by Gustavo Niemeyer
Status: Merged
Merged at revision: 48
Proposed branch: lp:~niemeyer/lbox/long-summary
Merge into: lp:lbox
Diff against target: 77 lines (+24/-0)
3 files modified
propose.go (+6/-0)
submit.go (+6/-0)
text.go (+12/-0)
To merge this branch: bzr merge lp:~niemeyer/lbox/long-summary
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+111099@code.launchpad.net

Description of the change

Prevent summaries from being over long.

https://codereview.appspot.com/6302100/

To post a comment you must log in.
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Please take a look.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Reviewers: mp+111099_code.launchpad.net,

Message:
Please take a look.

Description:
Prevent summaries from being over long.

https://code.launchpad.net/~niemeyer/lbox/long-summary/+merge/111099

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6302100/

Affected files:
   A [revision details]
   M propose.go
   M submit.go
   M text.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: propose.go
=== modified file 'propose.go'
--- propose.go 2012-03-15 02:05:35 +0000
+++ propose.go 2012-06-19 20:04:41 +0000
@@ -238,6 +238,12 @@
     return
    }
   }
+ for newLog.SummaryTooLong() {
+ newLog, err = editLog(newLog)
+ if failed(err) {
+ return
+ }
+ }
   if !*proposeCr && newLog.CodeReviewId != 0 {
    // Branch is already linked to a codereview, so use -cr implicitly.
    *proposeCr = true

Index: submit.go
=== modified file 'submit.go'
--- submit.go 2012-03-15 15:31:12 +0000
+++ submit.go 2012-06-19 20:05:44 +0000
@@ -94,6 +94,12 @@
   if failed(err) {
    return
   }
+ for newLog.SummaryTooLong() {
+ newLog, err = editLog(newLog)
+ if failed(err) {
+ return
+ }
+ }
   message := newLog.String()

   // --- Update log and load data from Launchpad and Rietveld ---

Index: text.go
=== modified file 'text.go'
--- text.go 2012-02-08 01:30:18 +0000
+++ text.go 2012-06-19 20:09:16 +0000
@@ -24,6 +24,10 @@
   return t.Summary != other.Summary || t.Description != other.Description
  }

+func (t *Log) SummaryTooLong() bool {
+ return len(t.Summary) > 72
+}
+
  func (t *Log) String() string {
   if t.Description == "" {
    return t.Summary + "\n"
@@ -34,6 +38,7 @@
  const (
   templateSummary = "<enter change summary here>"
   templateDescription = "<enter change description here if sensible>"
+ templateTooLong = "[TOO LONG] "
  )

  func editLog(oldLog *Log) (newLog *Log, err error) {
@@ -52,6 +57,10 @@

   if oldLog == nil {
    _, err = fmt.Fprintf(f, "%s\n\n%s\n", templateSummary,
templateDescription)
+ } else if oldLog.SummaryTooLong() {
+ longLog := *oldLog
+ longLog.Summary = templateTooLong + longLog.Summary
+ _, err = fmt.Fprintf(f, "%s", &longLog)
   } else {
    _, err = fmt.Fprintf(f, "%s", oldLog)
   }
@@ -73,6 +82,9 @@
   f.Seek(0, 0)
   data, err := ioutil.ReadAll(f)
   newLog = parseLog(data)
+ if strings.HasPrefix(newLog.Summary, templateTooLong) {
+ newLog.Summary = newLog.Summary[len(templateTooLong):]
+ }
   if newLog.Summary == "" || newLog.Summary == templateSummary {
    return nil, fmt.Errorf("Change summary is empty.")
   }

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

*** Submitted:

Prevent summaries from being over long.

R=
CC=
https://codereview.appspot.com/6302100

https://codereview.appspot.com/6302100/

Revision history for this message
Martin Packman (gz) wrote :

Thanks. Looks alright to my limited knowledge of the language (spell
while loops with 'for' huh?)

The different handling of long subject vs. no subject seems like a minor
wrinkle. Looping on Log validity instead might be neater, provided it is
still escapable. Giving a hint of how long might be nice, rather than
leaving it to trial and error for the user. (With git review I noticed I
get some vim highlight thing that changes colour at 50 characters, but
that's not in scope here.)

https://codereview.appspot.com/6302100/

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Applied your suggestions on https://codereview.appspot.com/6305112

Except for the behavior on an empty log. This is a well known way to
cancel the action on that kind of software (bzr, git, etc), and I'm keen
on preserving that.

https://codereview.appspot.com/6302100/

Revision history for this message
Martin Packman (gz) wrote :

> Except for the behavior on an empty log. This is a well known way to
cancel the
> action on that kind of software (bzr, git, etc), and I'm keen on
preserving
> that.

Thanks. What I was getting at is that, if I read the current logic
correctly, that the exit is triggered by an empty summary, not an empty
log - for instance a leading blank link.

https://codereview.appspot.com/6302100/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'propose.go'
2--- propose.go 2012-03-15 02:05:35 +0000
3+++ propose.go 2012-06-19 20:11:18 +0000
4@@ -238,6 +238,12 @@
5 return
6 }
7 }
8+ for newLog.SummaryTooLong() {
9+ newLog, err = editLog(newLog)
10+ if failed(err) {
11+ return
12+ }
13+ }
14 if !*proposeCr && newLog.CodeReviewId != 0 {
15 // Branch is already linked to a codereview, so use -cr implicitly.
16 *proposeCr = true
17
18=== modified file 'submit.go'
19--- submit.go 2012-03-15 15:31:12 +0000
20+++ submit.go 2012-06-19 20:11:18 +0000
21@@ -94,6 +94,12 @@
22 if failed(err) {
23 return
24 }
25+ for newLog.SummaryTooLong() {
26+ newLog, err = editLog(newLog)
27+ if failed(err) {
28+ return
29+ }
30+ }
31 message := newLog.String()
32
33 // --- Update log and load data from Launchpad and Rietveld ---
34
35=== modified file 'text.go'
36--- text.go 2012-02-08 01:30:18 +0000
37+++ text.go 2012-06-19 20:11:18 +0000
38@@ -24,6 +24,10 @@
39 return t.Summary != other.Summary || t.Description != other.Description
40 }
41
42+func (t *Log) SummaryTooLong() bool {
43+ return len(t.Summary) > 72
44+}
45+
46 func (t *Log) String() string {
47 if t.Description == "" {
48 return t.Summary + "\n"
49@@ -34,6 +38,7 @@
50 const (
51 templateSummary = "<enter change summary here>"
52 templateDescription = "<enter change description here if sensible>"
53+ templateTooLong = "[TOO LONG] "
54 )
55
56 func editLog(oldLog *Log) (newLog *Log, err error) {
57@@ -52,6 +57,10 @@
58
59 if oldLog == nil {
60 _, err = fmt.Fprintf(f, "%s\n\n%s\n", templateSummary, templateDescription)
61+ } else if oldLog.SummaryTooLong() {
62+ longLog := *oldLog
63+ longLog.Summary = templateTooLong + longLog.Summary
64+ _, err = fmt.Fprintf(f, "%s", &longLog)
65 } else {
66 _, err = fmt.Fprintf(f, "%s", oldLog)
67 }
68@@ -73,6 +82,9 @@
69 f.Seek(0, 0)
70 data, err := ioutil.ReadAll(f)
71 newLog = parseLog(data)
72+ if strings.HasPrefix(newLog.Summary, templateTooLong) {
73+ newLog.Summary = newLog.Summary[len(templateTooLong):]
74+ }
75 if newLog.Summary == "" || newLog.Summary == templateSummary {
76 return nil, fmt.Errorf("Change summary is empty.")
77 }

Subscribers

People subscribed via source and target branches

to all changes: