Skip to content

change git log order,add status type "Rename". #53

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from common import *
from clearcase import cc
from status import Modify, Add, Delete, Rename, SymLink
from status import Modify, Add, Delete, Rename, RenameModify, SymLink
import filecmp
from os import listdir
from os.path import isdir
Expand All @@ -29,7 +29,7 @@ def main(force=False, no_deliver=False, initial=False, all=False, cclabel=''):
if force:
IGNORE_CONFLICTS=True
cc_exec(['update', '.'], errors=False)
log = ['log', '-z', '--reverse', '--pretty=format:'+ LOG_FORMAT ]
log = ['log', '-z', '--reverse', '--topo-order', '--pretty=format:'+ LOG_FORMAT ]
if not all:
log.append('--first-parent')
if not initial:
Expand All @@ -50,6 +50,8 @@ def main(force=False, no_deliver=False, initial=False, all=False, cclabel=''):
reset.main('HEAD')

def getStatuses(id, initial):
modifylist = None

cmd = ['diff','--name-status', '-M', '-z', '--ignore-submodules', '%s^..%s' % (id, id)]
if initial:
cmd = cmd[:-1]
Expand All @@ -58,7 +60,7 @@ def getStatuses(id, initial):
status = git_exec(cmd)
status = status.strip()
status = status.strip("\x00")
types = {'M':Modify, 'R':Rename, 'D':Delete, 'A':Add, 'C':Add, 'S':SymLink}
types = {'M':Modify, 'R':Rename, 'RM': RenameModify, 'D':Delete, 'A':Add, 'C':Add, 'S':SymLink}
list = []
split = status.split('\x00')
while len(split) > 1:
Expand All @@ -71,6 +73,10 @@ def getStatuses(id, initial):
args.append(id)
if char == 'R':
args.append(split.pop(0))
if (modifylist == None):
modifylist = getFileModifyInfo(id)
if (args[1] in modifylist):
char = "RM"
elif char == 'C':
args = [split.pop(0)]
if args[0] == cache.FILE:
Expand All @@ -80,6 +86,20 @@ def getStatuses(id, initial):
list.append(type)
return list

def getFileModifyInfo(id):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong but we could just use the existence of R100 in --name-status -M from the previous call to avoid having to make a second call like this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when move or rename a file,we can modify it or not.
can not get the file modify status by --name-stauts.
so call diff by --numstat to check modify status.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when move or rename a file,we can modify it or not. can not get the file modify status by --name-stauts.

When a file is moved, --name-status shows the percentage of how much was moved. 100% (ie R100) would be the same as a full rename (and no changes). Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understane the number after R, and not found which code of this number .Sorry for that.
I'll modify for rename with no change check.

modifyFileList = []
cmd = ['diff', '--numstat', "-M", '--diff-filter=R', '-z', '--ignore-submodules', '%s^..%s' % (id, id)]
status = git_exec(cmd)
split = status.split('\x00')
while len(split) > 3:
changes = split.pop(0).split()
oldname = split.pop(0)
newname = split.pop(0)
if int(changes[0]) != 0 or int(changes[1]) != 0:
modifyFileList.append(newname)
return modifyFileList


def checkout(stats, comment, initial):
"""Poor mans two-phase commit"""
transaction = ITransaction(comment) if initial else Transaction(comment)
Expand Down
12 changes: 12 additions & 0 deletions status.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def commit(self, t):
cc_exec(['rm', self.file])

class Rename(Status):
def __init__(self, files):
self.old = files[0]
self.new = files[1]
self.setFile(self.new)
def stage(self, t):
t.stageDir(dirname(self.old))
self.stageDirs(t)
def commit(self, t):
self.commitDirs(t)
cc_exec(['mv', '-nc', self.old, self.new])

class RenameModify(Rename):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share more of the base class where possible? Like __init__ and the first part of commit?

def __init__(self, files):
self.old = files[0]
self.new = files[1]
Expand Down