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
=== modified file 'bazaar.go'
--- bazaar.go 2012-03-15 02:02:17 +0000
+++ bazaar.go 2012-10-30 12:03:25 +0000
@@ -14,7 +14,6 @@
1414
15import (15import (
16 "bytes"16 "bytes"
17 "errors"
18 "fmt"17 "fmt"
19 "io"18 "io"
20 "io/ioutil"19 "io/ioutil"
@@ -23,33 +22,36 @@
23 "strings"22 "strings"
24)23)
2524
26var logRevId = []byte("\nrevision-id: ")25func revisionInfoFromOutput(output string) (revisionId string, err error) {
26 fields := strings.Fields(output)
27 if len(fields) <= 1 || len(fields) > 2 {
28 err = fmt.Errorf("could not understand the output of bzr revision-info: %q", output)
29 } else {
30 // [0] is the revno, [1] is the revision-id
31 revisionId = fields[1]
32 }
33 return
34}
2735
28// BazaarDiffBranches returns a Delta between the bazaar branch at36// BazaarDiffBranches returns a Delta between the bazaar branch at
29// oldPath and the one at newPath.37// oldPath and the one at newPath.
30func BazaarDiffBranches(oldPath, newPath string) (Delta, error) {38func BazaarDiffBranches(oldPath, newPath string) (Delta, error) {
31 output1, _, err := run("bzr", "log", "-l1", "--show-ids", "-r", "ancestor:"+oldPath, newPath)39 output1, _, err := run("bzr", "revision-info", "-r", "ancestor:"+oldPath, "-d", newPath)
32 if err != nil {40 if err != nil {
33 return nil, err41 return nil, err
34 }42 }
35 output2, _, err := run("bzr", "log", "-l1", "--show-ids", newPath)43 output2, _, err := run("bzr", "revision-info", "-r", "-1", "-d", newPath)
36 if err != nil {44 if err != nil {
37 return nil, err45 return nil, err
38 }46 }
39 i1 := bytes.Index(output1, logRevId)47 oldRevision, err := revisionInfoFromOutput(string(output1))
40 i2 := bytes.Index(output2, logRevId)48 if err != nil {
41 if i1 < 0 || i2 < 0 {49 return nil, err
42 return nil, errors.New("no revision-id in bzr log output")50 }
43 }51 newRevision, err := revisionInfoFromOutput(string(output2))
44 output1 = output1[i1+len(logRevId):]52 if err != nil {
45 output2 = output2[i2+len(logRevId):]53 return nil, err
46 i1 = bytes.Index(output1, []byte{'\n'})54 }
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 return &bzrBranches{oldPath, newPath, oldRevision, newRevision}, nil55 return &bzrBranches{oldPath, newPath, oldRevision, newRevision}, nil
54}56}
5557

Subscribers

People subscribed via source and target branches