NavicoOS / ac2git

Tool to convert an AccuRev repository to Git.
29 stars 15 forks source link

multiple mkstream transaction match #85

Closed marcnorthover closed 8 years ago

marcnorthover commented 8 years ago

I received this error:

  File "ac2git.py", line 1255, in RetrieveStreamInfo
    deepHist = accurev.ext.deep_hist(depot=depot, stream=stream.name, timeSpec="{0}-{1}".format(tr.id, endTr.id), ignoreTimelocks=
ignoreTimelocks, useCache=self.config.accurev.UseCommandCache())
  File "C:\git_work\ac2git-0.6\accurev.py", line 2564, in deep_hist
    mkstreamTr = ext.get_mkstream_transaction(stream=streamInfo.streamNumber, depot=depot, useCache=useCache)
  File "C:\git_work\ac2git-0.6\accurev.py", line 2377, in get_mkstream_transaction
    raise Exception("Invariant error! Ambiguous: multiple mkstream transactions match! Could not determine if stream {s} (name: {n
}, id: {sn}) was created by transaction {t1} or {t2}!".format(s=stream, n=streamInfo.name, sn=streamInfo.streamNumber, t1=mkstream
Tr.id, t2=t.id))
Exception: Invariant error! Ambiguous: multiple mkstream transactions match! Could not determine if stream 587 (name: xxxxxxxxxxxx-2014-01-07, id: 587) was created by transaction 10063 or 10062!

Sure enough in accurev I have 2 transactions from 2 separate projects with the same timestamp:

C:\accurev_work\AM-accessmanager-local\accessmanager-local>accurev hist -fx -t 10062-10063
<?xml version="1.0" encoding="utf-8"?>
<AcResponse
    Command="hist"
    TaskId="3568090">
  <transaction
      id="10062"
      type="mkstream"
      time="1418660369"
      user="aaaaaaaaa">
    <stream
        name="yyyyyyyyyyy-2007-10-23"
        streamNumber="586"
        depotName="zzzzzzzzz"
        type="snapshot"
        basis="yyyyyyyyyy"
        basisStreamNumber="23"/>
  </transaction>
  <transaction
      id="10063"
      type="mkstream"
      time="1418660369"
      user="bbbbbbbbb">
    <stream
        name="ccccccccccc-2014-01-07"
        streamNumber="587"
        depotName="zzzzzzzzzz"
        type="snapshot"
        basis="ccccccccccc"
        basisStreamNumber="21"/>
  </transaction>
</AcResponse>

Any suggestions on a fix for this one? If there are more than 1, seems like we can for loop thru and find the one that matches the given stream name?

fatfreddie commented 8 years ago

I'm not familiar enough with the code but it seems to me there are two possible resolutions. Either run accurev hist -fx -t 10063, or search the output for transaction 10063. I am assuming that transaction 10063 is being processed at this point.

I wonder how the code determines that a transaction range is needed, and if it can be modified to use only one (correct) transaction in this case.

ghost commented 8 years ago

You could replace this if statement with a check that looks at the result of the accurev show streams command before and after the found mkstream transaction and if it is determined that our stream has been created here then we return that transaction.

I chose not to do that because it was much, much slower.

ghost commented 8 years ago

Replace this code with the following:

mkstreamTrList = []
for t in mkstreams.transactions:
    if GetTimestamp(t.time) == GetTimestamp(streamInfo.startTime):
        mkstreamTrList.append(t)
    elif GetTimestamp(t.time) < GetTimestamp(streamInfo.startTime):
        break # There's no point in looking for it any further than this since the transactions are sorted in descending order of transaction number and hence by time as well.

if len(mkstreamTrList) == 1:
    mkstreamTr = mkstreamTrList[0]
elif len(mkstreamTrList) > 1:
    # You're really, really unlucky here.
    for t in mkstreamTrList:
        before = show.streams(depot=depot, timeSpec=(t.id - 1)).getStream(streamInfo.streamNumber)
        after = show.streams(depot=depot, timeSpec=(t.id)).getStream(streamInfo.streamNumber)
        if before is None and after is not None:
            mkstreamTr = t
            break

Which should fix it...

ghost commented 8 years ago

If that patch does fix it (and you've tested it does what is expected) please commit it & supply it back so I can merge it in.

marcnorthover commented 8 years ago

The fix seems to work just fine. I created a fork and a branch with the patch and merged it back to the master. Let me know if anything else is required.

ghost commented 8 years ago

Though I wanted you to make a pull request from your fork to our upstream it doesn't matter in the end since GitHub allows me to make pull requests from any fork. This is what I've done and I've incorporated your changes in our master branch.

Thanks for supplying the patch! I hope that this makes up for me stealing that other issue from under you... Your name should now be in the contributors list.