Skip to content

For a deleted file, invalid diff received #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pratikjain1993 opened this issue Oct 16, 2016 · 8 comments
Closed

For a deleted file, invalid diff received #534

pratikjain1993 opened this issue Oct 16, 2016 · 8 comments

Comments

@pratikjain1993
Copy link

pratikjain1993 commented Oct 16, 2016

I have received the following diff object for a file which I had deleted in the commit : c9050a81069d94b9b9692589608ec8f8d6c52827 .

myFile = {Diff} webapp/META-INF/ion-config/EU/pipeline_context_data/R2L/UK_R2l_SOA_SILVER/BankAccountFragment/InputSets/DE_IBAN.ion\n=======================================================\nlhs: None\nrhs: 100644 | e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\nfile added in rhs
 NULL_BIN_SHA = {str} '��������������������'
 NULL_HEX_SHA = {str} '0000000000000000000000000000000000000000'
 a_blob = {NoneType} None
 a_mode = {int} 33188
 a_path = {unicode} u'webapp/META-INF/ion-config/EU/pipeline_context_data/R2L/UK_R2l_SOA_SILVER/BankAccountFragment/InputSets/DE_IBAN.ion'
 a_rawpath = {str} 'webapp/META-INF/ion-config/EU/pipeline_context_data/R2L/UK_R2l_SOA_SILVER/BankAccountFragment/InputSets/DE_IBAN.ion'
 b_blob = {Blob} e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
 b_mode = {int} 33188
 b_path = {unicode} u'webapp/META-INF/ion-config/EU/pipeline_context_data/R2L/UK_R2l_SOA_SILVER/BankAccountFragment/InputSets/DE_IBAN.ion'
 b_rawpath = {str} 'webapp/META-INF/ion-config/EU/pipeline_context_data/R2L/UK_R2l_SOA_SILVER/BankAccountFragment/InputSets/DE_IBAN.ion'

What I understood was that I should receive b_path/b_blob/b_mode as none, but it seems not to be working fine.

@Byron
Copy link
Member

Byron commented Oct 16, 2016

Is this issue similar to this one: #531 ?
Otherwise I would be tempted to close this one, as it is impossible to understand what is expected, and how to reproduce the issue with GitPython.

@pratikjain1993
Copy link
Author

pratikjain1993 commented Oct 16, 2016

My Source code:

import os
import whatthepatch
from git import Repo
import unicodedata

#workspacePath = os.getcwd()
workspacePath = '/Users/jainprat/jainprat-SWIPERTOL/src/SWIPERTOLWebStack'
repo = Repo(workspacePath)
repo.config_reader()
cln = raw_input('Enter the commit id: ')
hcommit = repo.commit(cln)
oldCommit = hcommit.parents[0]
hcommit.diff()  # diff tree against index
mydiff = hcommit.diff(oldCommit, create_patch=True)
outputFile = open('output.ion','w')


def getIonStartingEndingLineTuple(ionStartingAndEndingLineNumbersTuples, changedLineNumber):
    for entry in ionStartingAndEndingLineNumbersTuples:
        if changedLineNumber >= entry[0] and changedLineNumber <= entry[1]:
            return entry
    return None


def getStartingEndingLineNumbersForIon(allLines):
    result = []
    lineNumber = -1
    bracesCount = 0
    entry = []
    for line in allLines:
        lineNumber += 1
        if "{" in line:
            if bracesCount == 0:
                entry.append(lineNumber)
            bracesCount += 1
        if "}" in line:
            bracesCount -= 1
            if bracesCount == 0:
                entry.append(lineNumber)
                result.append(entry)
                entry = []
    return result

def getChangedIons(myFilePath, addedLineNumbers, removedLineNumbers, modifiedLineNumbers):
    changedIons = ""
    if len(removedLineNumbers) > 0 or len(modifiedLineNumbers) > 0 :
        unicodeContents = repo.git.show('{}:{}'.format(oldCommit.hexsha,myFilePath))
        oldFileContent = unicodedata.normalize('NFKD',unicodeContents).encode('ascii','ignore')
        oldFileContent = oldFileContent.split('\n')
        oldFileStartingAndEndingLineNumbersTupleList = getStartingEndingLineNumbersForIon(oldFileContent)
    unicodeContents = repo.git.show('{}:{}'.format(hcommit.hexsha,myFilePath))
    newFileContent = unicodedata.normalize('NFKD',unicodeContents).encode('ascii','ignore')
    newFileContent = newFileContent.split('\n')
    newFileStartingAndEndingLineNumbersTupleList = getStartingEndingLineNumbersForIon(newFileContent)

    changedEntries = set([])
    entry = None
    for lineNumber in addedLineNumbers:
        if entry != None and lineNumber >= entry[0] and lineNumber <= entry[1]:
            continue
        entry = getIonStartingEndingLineTuple(newFileStartingAndEndingLineNumbersTupleList,lineNumber)
        if entry != None:
            changedEntries.add(tuple(entry))
    entry = None
    for lineNumber in modifiedLineNumbers:
        if entry != None and lineNumber >= entry[0] and lineNumber <= entry[1]:
            continue
        entry = getIonStartingEndingLineTuple(newFileStartingAndEndingLineNumbersTupleList, lineNumber)
        if entry != None:
            changedEntries.add(tuple(entry))
    entry = None
    for lineNumber in removedLineNumbers:
        if entry != None and lineNumber >= entry[0] and lineNumber <= entry[1]:
            continue
        entry = getIonStartingEndingLineTuple(oldFileStartingAndEndingLineNumbersTupleList, lineNumber)
        if entry == None:
            continue
        flag = True
        for i in range(entry[0],entry[1]):
            if i not in removedLineNumbers:
                flag = False
                break;
        if flag:
            changedEntries.add(tuple(entry))
    for changedEntry in changedEntries:
        for i in range(changedEntry[0],changedEntry[1]+1):
            changedIons = changedIons+"\n"+newFileContent[i]
    return changedIons

for myFile in mydiff:
    **myFileAPath = myFile.a_path
    myFileBPath = myFile.b_path**
    if myFileBPath != None and myFileBPath.endswith('.ion'):
        print myFileBPath
        modifiedLineNumbers = set([])
        addedLineNumbers = set([])
        removedLineNumbers = set([])
        parsedDiff = whatthepatch.parse_patch(myFile.diff)
        for content in parsedDiff:
            for change in content.changes:
                if change[1] != None and change[0] != None:
                    modifiedLineNumbers.add(change[1])
                elif change[0] == None:
                    removedLineNumbers.add(change[0])
                else:
                    addedLineNumbers.add(change[1])
        outputFile.write(getChangedIons(myFileBPath, addedLineNumbers, removedLineNumbers, modifiedLineNumbers))
    elif myFileBPath == None and myFile.a_path != None:
        myFileBPath = myFile.a_path
        print myFileBPath
        unicodeContents = repo.git.show('{}:{}'.format(hcommit.hexsha, myFileBPath))
        newFileContent = unicodedata.normalize('NFKD', unicodeContents).encode('ascii', 'ignore')
        outputFile.write(newFileContent)
outputFile.close()

I believe that this could be related to #531 since this seems to be an issue with deleted/added file too.
If you see the bold font code, for a deleted file in the diff, both myFileAPath and myFileBPath are not None.

@Byron
Copy link
Member

Byron commented Oct 16, 2016

Thank you! Could you please reduce this to the smallest amount of self-contained code that still shows the issue you are describing ?

@pratikjain1993
Copy link
Author

pratikjain1993 commented Oct 16, 2016

Sorry for giving such a large piece of code:
Here is the meaningful code required:

workspacePath = '/Users/jainprat/jainprat-SWIPERTOL/src/SWIPERTOLWebStack'
repo = Repo(workspacePath)
repo.config_reader()
cln = raw_input('Enter the commit id: ')
hcommit = repo.commit(cln)
oldCommit = hcommit.parents[0]
hcommit.diff()  # diff tree against index
mydiff = hcommit.diff(oldCommit, create_patch=True)

for myFile in mydiff:
    myFileAPath = myFile.a_path
    myFileBPath = myFile.b_path

here , both myFileAPath and myFileBPath are not none in case of a
deleted file for me.

On Sun, Oct 16, 2016 at 11:47 PM, Sebastian Thiel [email protected]
wrote:

Thank you! Could you please reduce this to the smallest amount of
self-contained code that still shows the issue you are describing ?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#534 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVz5LoHUMCvSwPHMR2EXL9eE5lYDkTiKks5q0mpPgaJpZM4KX_Xp
.

@Byron
Copy link
Member

Byron commented Oct 16, 2016

Unfortunately, this is still not an example that can make the issue reproducible on a machine that is not yours. It requires input, and a repository that is not publicly accessible. You can have a look at this extraordinary example, which can be found in this issue.

What I wonder is if the suggestion of #531 of just inverting the code would work for you.

@pratikjain1993
Copy link
Author

Does inverting not imply that b*** will be replaced by a*** ? If yes, my issue will still persist.
Do not have a github public repo yet. Will create one and try to reproduce and revert back to you here.

@pratikjain1993
Copy link
Author

Not able to repro on a new repo.
Need to look what could be different for my use case.

@Byron
Copy link
Member

Byron commented Mar 8, 2017

I am closing this issue as it had no interaction for more than 3 months. Please feel free to comment in case you need it to be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants