Skip to content
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

cloc --git-diff-rel does not respond correctly count #799

Closed
houwen0 opened this issue Jan 3, 2024 · 8 comments
Closed

cloc --git-diff-rel does not respond correctly count #799

houwen0 opened this issue Jan 3, 2024 · 8 comments

Comments

@houwen0
Copy link

houwen0 commented Jan 3, 2024

Describe the bug
cloc counts respond incorrectly count when counting diffs between 2 commits

cloc; OS; OS version

  • cloc version: 1.98
  • OS:Windows10 professional
  • OS version: 22H2

To Reproduce

  1. cloc-1.98 --diff 39a54ce3 66ec3dfe

  2. the result
    image

  3. refer to the commit different of gitlab

image
image

Expected result
I expect the modified code to be 7, the added code to be 1 or 0,the removed code to be 1.

@AlDanial
Copy link
Owner

AlDanial commented Jan 4, 2024

I'll need the two versions of these files to reproduce the problem. Can you post them?

@houwen0
Copy link
Author

houwen0 commented Jan 8, 2024

The above screenshot is the commit provided by Gitlab, and I can provide you with these two source files:

1、SsoController

package com.test.svc.web.controller;

import com.test.svc.common.constant.ServiceExceptionCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.test.framework.auditlog.expection.ServiceException;
import top.test.framework.auth.client.UnifyAuthContextHolder;
import top.test.framework.auth.client.annotation.Authorize;
import top.test.framework.auth.facade.authrization.AuthContext;
import top.test.framework.auth.facade.constant.AuthConstant;
import top.test.framework.auth.facade.entity.UserInfo;
import top.test.framework.biz.ro.TestResult;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/sso")
public class SsoController {

@GetMapping("/authorize")
@Authorize()
public TestResult<String> authorize(HttpServletRequest request) {
    AuthContext authContext = (AuthContext) request.getServletContext().getAttribute(AuthConstant.AUTH_CONTEXT_KEY);
    return TestResult.success(ServiceExceptionCode.SUCCESS.code,"process success",authContext.getUserInfo().getUsername());
}

@GetMapping("/unauthorize")
public TestResult<String> unAuthorize( ) {
    return TestResult.success(ServiceExceptionCode.SUCCESS.code,"process success","No verification is required !");
}

@GetMapping("/authorize/userInfo")
@Authorize()
public TestResult<UserInfo> authorizeUserInfo(HttpServletRequest request) {
    UserInfo userInfo  = UnifyAuthContextHolder.getUserInfo();

// AuthContext authContext = (AuthContext) request.getServletContext().getAttribute(AuthConstant.AUTH_CONTEXT_KEY);
return TestResult.success(ServiceExceptionCode.SUCCESS.code,"process success",userInfo);
}

}

2、SysInfoController

package com.test.svc.web.controller.svc_govern;

import com.test.svc.common.constant.ServiceExceptionCode;
import com.test.svc.core.service.impl.svc_govern.SysInfoServiceImpl;
import org.springframework.web.bind.annotation.*;
import top.test.framework.auth.client.annotation.Authorize;
import top.test.framework.biz.ro.TestResult;
import javax.annotation.Resource;
import com.test.svc.dal.po.svc_govern.mbg.SysInfo;
import top.test.framework.biz.ro.PagedTestResult;

/**
*
*/
@RestController
@RequestMapping("/sysInfo")
public class SysInfoController {

@Resource
private SysInfoServiceImpl sysInfoService;



/**
* 新增
*/
@PostMapping("")
@Authorize(roles = {},authorities ={})
public TestResult insert(@RequestBody SysInfo sysInfo){
    sysInfoService.insert(sysInfo);
    return TestResult.success(ServiceExceptionCode.SUCCESS.code,null,null);
}


/**
* 更新
*/
@PutMapping("")
@Authorize(roles = {},authorities ={})
public TestResult<String> update(@RequestBody SysInfo sysInfo){
    sysInfoService.update(sysInfo);
    return TestResult.success( ServiceExceptionCode.SUCCESS.code,null,null);
}

/**
* Load查询
*/
@GetMapping("/{id}")
@Authorize(roles = {},authorities ={})
public TestResult<SysInfo> load(@PathVariable long id){
    return TestResult.success(ServiceExceptionCode.SUCCESS.code,null, sysInfoService.load(id));
}

@GetMapping("/pageShow/pageNum/{pageNum}/pageSize/{pageSize}")
@Authorize(roles = {},authorities ={})
public PagedTestResult<SysInfo> page(@PathVariable int pageNum, @PathVariable int pageSize){
    return  sysInfoService.showPage(pageNum,pageSize);
}

}

@houwen0
Copy link
Author

houwen0 commented Jan 8, 2024

I am not sure if the “git diff” is a usage issue or if the function is incomplete. If there are any usage issues, please tell me the correct method

@AlDanial
Copy link
Owner

AlDanial commented Jan 8, 2024

I don't think the content you posted is consistent with the results you showed. I have attached the files as you provided them. These two files have little in common. When I run cloc --diff SsoController.java SysInfoController.java I get

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Java
 same                            0              0              0              8
 modified                        1              0              1             19
 added                           0              4             11             10
 removed                         0              0              0              6
-------------------------------------------------------------------------------
SUM:
 same                            0              0              0              8
 modified                        1              0              1             19
 added                           0              4             11             10
 removed                         0              0              0              6
-------------------------------------------------------------------------------

If you attach the files rather than cut/paste their contents it will be easier to work with them.
SysInfoController.java.txt
SsoController.java.txt

@houwen0
Copy link
Author

houwen0 commented Jan 8, 2024

sorry,What I am comparing is not these two files, but the two commit attempts of Gitlab。The command I executed is as follows:
cloc-1.98 --git-diff-rel 39a54ce3 66ec3dfe

"39a54ce3" or "66ec3dfe" is gitlab's commit id

@AlDanial
Copy link
Owner

Based on your screenshot, your commits refer to two files each. When you tell cloc to diff the two commits you are really saying "compare the files between these two commits". To reproduce this problem I'll either need to clone your git repo or to get the four files themselves.

@houwen0
Copy link
Author

houwen0 commented Jan 11, 2024

Sorry, the real files are confidential. I'm wondering if you support the "git diff" feature. I want to use this feature to count the changes made in a git commit, such as additions, modifications, and deletions.

@AlDanial
Copy link
Owner

cloc uses internal logic to compute diffs between two commits (the output from git diff by itself is not sufficient to compute comment and code changes), so yes, it does support the capability you want.

However, without the input files, I won't be able to tell why the results are not as you expect. If you encounter this problem with files you are able to distribute, please open a new issue.

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

No branches or pull requests

2 participants