Merge lp:~jameinel/goetveld/fix-log into lp:goetveld

Proposed by John A Meinel
Status: Needs review
Proposed branch: lp:~jameinel/goetveld/fix-log
Merge into: lp:goetveld
Diff against target: 70 lines (+26/-24)
1 file modified
bazaar.go (+26/-24)
To merge this branch: bzr merge lp:~jameinel/goetveld/fix-log
Reviewer Review Type Date Requested Status
The Go Language Gophers Pending
Review via email: mp+132060@code.launchpad.net

Description of the change

Handle some edge cases with 'bzr log'

You can alias 'bzr log' to set default arguments. Because of this, the output
doesn't conform to what rietveld expects. This just forces specific flags so
that the output will match expectations.

https://codereview.appspot.com/6822053/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Reviewers: mp+132060_code.launchpad.net,

Message:
Please take a look.

Description:
Handle some edge cases with 'bzr log'

You can alias 'bzr log' to set default arguments. Because of this, the
output
doesn't conform to what rietveld expects. This just forces specific
flags so
that the output will match expectations.

https://code.launchpad.net/~jameinel/goetveld/fix-log/+merge/132060

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M bazaar.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: bazaar.go
=== modified file 'bazaar.go'
--- bazaar.go 2012-03-15 02:02:17 +0000
+++ bazaar.go 2012-10-30 11:06:00 +0000
@@ -28,11 +28,11 @@
  // BazaarDiffBranches returns a Delta between the bazaar branch at
  // oldPath and the one at newPath.
  func BazaarDiffBranches(oldPath, newPath string) (Delta, error) {
- output1, _, err :=
run("bzr", "log", "-l1", "--show-ids", "-r", "ancestor:"+oldPath, newPath)
+ output1, _, err :=
run("bzr", "log", "--long", "-l1", "--show-ids", "-r", "ancestor:"+oldPath,
newPath)
   if err != nil {
    return nil, err
   }
- output2, _, err := run("bzr", "log", "-l1", "--show-ids", newPath)
+ output2, _, err :=
run("bzr", "log", "--long", "-l1", "--show-ids", "-r", "-1", newPath)
   if err != nil {
    return nil, err
   }

lp:~jameinel/goetveld/fix-log updated
42. By John A Meinel

rietveld/bazaar: use 'bzr revision-info' instead of 'bzr log'

We don't need to deal with lots of flags to 'bzr log', instead use
'bzr revision-info' which just gives us the data we actually care
about.
Also, 'strings.Fields' is a simpler way to parse then doing
string searching for the right context.

Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :

Poke about getting a review on this?

Unmerged revisions

42. By John A Meinel

rietveld/bazaar: use 'bzr revision-info' instead of 'bzr log'

We don't need to deal with lots of flags to 'bzr log', instead use
'bzr revision-info' which just gives us the data we actually care
about.
Also, 'strings.Fields' is a simpler way to parse then doing
string searching for the right context.

41. By John A Meinel

Change the use of 'bzr log' to force the format.

If you have any aliases defined, then bzr log can actually use
a different format, and the bazaar code won't be able to determine
the actual revision id. (eg --short puts ' revision-id:revid' rather
than 'revision-id: revid'.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bazaar.go'
2--- bazaar.go 2012-03-15 02:02:17 +0000
3+++ bazaar.go 2012-10-30 12:03:25 +0000
4@@ -14,7 +14,6 @@
5
6 import (
7 "bytes"
8- "errors"
9 "fmt"
10 "io"
11 "io/ioutil"
12@@ -23,33 +22,36 @@
13 "strings"
14 )
15
16-var logRevId = []byte("\nrevision-id: ")
17+func revisionInfoFromOutput(output string) (revisionId string, err error) {
18+ fields := strings.Fields(output)
19+ if len(fields) <= 1 || len(fields) > 2 {
20+ err = fmt.Errorf("could not understand the output of bzr revision-info: %q", output)
21+ } else {
22+ // [0] is the revno, [1] is the revision-id
23+ revisionId = fields[1]
24+ }
25+ return
26+}
27
28 // BazaarDiffBranches returns a Delta between the bazaar branch at
29 // oldPath and the one at newPath.
30 func BazaarDiffBranches(oldPath, newPath string) (Delta, error) {
31- output1, _, err := run("bzr", "log", "-l1", "--show-ids", "-r", "ancestor:"+oldPath, newPath)
32- if err != nil {
33- return nil, err
34- }
35- output2, _, err := run("bzr", "log", "-l1", "--show-ids", newPath)
36- if err != nil {
37- return nil, err
38- }
39- i1 := bytes.Index(output1, logRevId)
40- i2 := bytes.Index(output2, logRevId)
41- if i1 < 0 || i2 < 0 {
42- return nil, errors.New("no revision-id in bzr log output")
43- }
44- output1 = output1[i1+len(logRevId):]
45- output2 = output2[i2+len(logRevId):]
46- i1 = bytes.Index(output1, []byte{'\n'})
47- i2 = bytes.Index(output2, []byte{'\n'})
48- if i1 < 0 || i2 < 0 {
49- return nil, errors.New("bad revision-id in bzr log output")
50- }
51- oldRevision := string(output1[:i1])
52- newRevision := string(output2[:i2])
53+ output1, _, err := run("bzr", "revision-info", "-r", "ancestor:"+oldPath, "-d", newPath)
54+ if err != nil {
55+ return nil, err
56+ }
57+ output2, _, err := run("bzr", "revision-info", "-r", "-1", "-d", newPath)
58+ if err != nil {
59+ return nil, err
60+ }
61+ oldRevision, err := revisionInfoFromOutput(string(output1))
62+ if err != nil {
63+ return nil, err
64+ }
65+ newRevision, err := revisionInfoFromOutput(string(output2))
66+ if err != nil {
67+ return nil, err
68+ }
69 return &bzrBranches{oldPath, newPath, oldRevision, newRevision}, nil
70 }
71

Subscribers

People subscribed via source and target branches