def suggestion_search(reason_commits, api, chg_type):
	os.chdir(LINUX_GIT)
	git_cmd = ''
	commits = []

	# find suggestions from reason commits
	if len(reason_commits) > 0:
		git_cmd = "git log -p -1 " + reason_commits[0].commit_id
		reason_patch = LogPatchSplitter(os.popen(git_cmd))
		for rp in reason_patch:
			rc = commit()
			if rc.full_commit_parser(rp) == True:
				commits.append(rc)

	if chg_type == 'DECL CHANGED':
		git_cmd = "git log --no-merges -p -2 -G'"
	else:
		git_cmd = "git log --no-merges -p -2 -S'"
	git_cmd += api + "' " + OLD_VER + ".." + NEW_VER + " -- drivers/"
	patches = LogPatchSplitter(os.popen(git_cmd))
	
	for p in patches:
		tmpc = commit()
		if tmpc.full_commit_parser(p) == True:
			commits.append(tmpc)
	os.chdir(CUR_DIR)
	return commits
def suggestion_search(reason_commits, api, chg_type):
    os.chdir(LINUX_GIT)
    git_cmd = ''
    commits = []

    # find suggestions from reason commits
    if len(reason_commits) > 0:
        git_cmd = "git log -p -1 " + reason_commits[0].commit_id
        reason_patch = LogPatchSplitter(os.popen(git_cmd))
        for rp in reason_patch:
            rc = commit()
            if rc.full_commit_parser(rp) == True:
                commits.append(rc)

    if chg_type == 'DECL CHANGED':
        git_cmd = "git log --no-merges -p -2 -G'"
    else:
        git_cmd = "git log --no-merges -p -2 -S'"
    git_cmd += api + "' " + OLD_VER + ".." + NEW_VER + " -- drivers/"
    patches = LogPatchSplitter(os.popen(git_cmd))

    for p in patches:
        tmpc = commit()
        if tmpc.full_commit_parser(p) == True:
            commits.append(tmpc)
    os.chdir(CUR_DIR)
    return commits
def commit_locate(api, fname, diff_type):
	rpath = get_relative_path(fname)
	os.chdir(LINUX_GIT)
	git_cmd = ''
	if diff_type.find("CHANGED") > 0 :
		git_cmd = "git log --no-merges -p -G'"
	else:
		git_cmd = "git log --no-merges -p -S'"
	git_cmd += api + "' " + OLD_VER + ".." + NEW_VER + " -- " + rpath[2:]
	# split all commits found
	found = os.popen(git_cmd)
	patches = LogPatchSplitter(found)
	commits = []
	# construct commit object for each commit with patch
	for p in patches:
		tmpc = commit()
		if tmpc.full_commit_parser(p) == True:
			commits.append(tmpc)
	os.chdir(CUR_DIR)
	return commits
def commit_locate(api, fname, diff_type):
    rpath = get_relative_path(fname)
    os.chdir(LINUX_GIT)
    git_cmd = ''
    if diff_type.find("CHANGED") > 0:
        git_cmd = "git log --no-merges -p -G'"
    else:
        git_cmd = "git log --no-merges -p -S'"
    git_cmd += api + "' " + OLD_VER + ".." + NEW_VER + " -- " + rpath[2:]
    # split all commits found
    found = os.popen(git_cmd)
    patches = LogPatchSplitter(found)
    commits = []
    # construct commit object for each commit with patch
    for p in patches:
        tmpc = commit()
        if tmpc.full_commit_parser(p) == True:
            commits.append(tmpc)
    os.chdir(CUR_DIR)
    return commits