Exemple #1
0
 def test_simple(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs["HEAD"] = c3.id
     outstream = StringIO()
     porcelain.log(self.repo.path, outstream=outstream)
     self.assertTrue(outstream.getvalue().startswith("-" * 50))
Exemple #2
0
def git_log(args):
    parser = argparse.ArgumentParser(description='git log arg parser')
    parser.add_argument('-f',
                        '--format',
                        action='store',
                        dest='format',
                        default=False)
    parser.add_argument('-o',
                        '--output',
                        action='store',
                        dest='output',
                        type=argparse.FileType('w'),
                        default=sys.stdout)

    parser.add_argument('-l',
                        '-n',
                        '--length',
                        action='store',
                        type=int,
                        dest='max_entries',
                        default=None)

    results = parser.parse_args(args)

    try:
        repo = _get_repo()
        porcelain.log(repo.repo.path,
                      max_entries=results.max_entries,
                      outstream=results.output)
    except ValueError:
        print command_help['log']
Exemple #3
0
def git_log(args):
    parser = argparse.ArgumentParser(description='git log arg parser')
    parser.add_argument('-f','--format',
                        action='store',
                        dest='format',
                        default=False)
    parser.add_argument('-o','--output',
                        action='store',
                        dest='output',
                        type=argparse.FileType('w'),
                        default=sys.stdout)

    parser.add_argument('-l','--length',
                        action='store',
                        type=int,
                        dest='max_entries',
                        default=None)

    results = parser.parse_args(args)

    try:
        repo = _get_repo()
        porcelain.log(repo.repo.path, max_entries=results.max_entries,outstream=results.output)
    except ValueError:
        print command_help['log']
Exemple #4
0
 def test_simple(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs[b"HEAD"] = c3.id
     outstream = BytesIO()
     porcelain.log(self.repo.path, outstream=outstream)
     self.assertEqual(3, outstream.getvalue().count(b"-" * 50))
Exemple #5
0
 def test_simple(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs["HEAD"] = c3.id
     outstream = BytesIO()
     porcelain.log(self.repo.path, outstream=outstream)
     self.assertEqual(3, outstream.getvalue().count("-" * 50))
Exemple #6
0
 def test_max_entries(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs[b"HEAD"] = c3.id
     outstream = StringIO()
     porcelain.log(self.repo.path, outstream=outstream, max_entries=1)
     self.assertEqual(1, outstream.getvalue().count("-" * 50))
Exemple #7
0
 def commit_logs(self):
     try:
         if os.path.exists(self.repo_path):
             print p.log(self.repo)
         else:
             print "Repo does not exist"
     except:
         print "No commits yet"
Exemple #8
0
	def commit_logs(self):
		try:
			if os.path.exists(self.repo_path):
				print p.log(self.repo)
			else:
				print "Repo does not exist"
		except:
			print "No commits yet"
Exemple #9
0
 def git_log(args):
     if len(args) <= 1:
         try:
             repo = _get_repo()
             porcelain.log(repo.repo, max_entries=int(args[0]) if len(args)==1 else None)
         except ValueError:
             print command_help['log']
     else:
         print command_help['log']
def example():
    print '=== Create folders and blobs ==='
    os.mkdir('git_test')
    repo = Repo.init('git_test')
    for x in range(5):
        r = Repo('git_test')
        s = Snapshot(r)

        root = s.root()
        print '$ ls'
        print root.nodes()
        dir1 = root.add_treenode('dir1')
        blob = dir1.add_blobnode('file1', 'content%s' % x)
        blob.save()

        dir2 = dir1.add_treenode('dir2')
        blob = dir2.add_blobnode('file2', 'content%s' % x)
        blob.save()
        dir2.save()

        dir1.save()
        root.save()

        print 'commit:', s.commit('testuser', message='test commit: %s' % x).id
        print '$ cat dir1/file1'
        print root.get_node('dir1').get_node('file1').read_data()
        print dir1.get_node('dir2').get_node('file2').read_data()
        print

    #Using Porcelain
    #Initiating a new repo
    repo = porcelain.init("myrepo")

    #cloning a repo from a server
    porcelain.clone("https://github.com/sugarlabs/browse-activity.git",
                    "browse_activity_clone")

    #local cloning
    porcelain.clone("/home/vikram/browse_activity_clone",
                    "browse_activity_clone_1")
    print
    print "Commiting"
    open("myrepo/testfile", "w").write("data")
    porcelain.add(repo, "myrepo/testfile")
    porcelain.commit(repo, "A sample commit")

    open("myrepo/testfile", "w").write("data1")
    porcelain.add(repo, "myrepo/testfile")
    porcelain.commit(repo, "Second commit")

    open("myrepo/testfile1", "w").write("sugar-labs")
    porcelain.add(repo, "myrepo/testfile1")
    porcelain.commit(repo, "First commit")

    print "Commit Logs:"
    print porcelain.log(repo)
def example():
    print '=== Create folders and blobs ==='
    os.mkdir('git_test')
    repo = Repo.init('git_test')
    for x in range(5):
        r = Repo('git_test')
        s = Snapshot(r)

        root = s.root()
        print '$ ls'
        print root.nodes()
        dir1 = root.add_treenode('dir1')
        blob = dir1.add_blobnode('file1', 'content%s' % x)
        blob.save()

        dir2 = dir1.add_treenode('dir2')
        blob = dir2.add_blobnode('file2', 'content%s' % x)
        blob.save()
        dir2.save()

        dir1.save()
        root.save()

        print 'commit:', s.commit('testuser', message='test commit: %s' % x).id
        print '$ cat dir1/file1'
        print root.get_node('dir1').get_node('file1').read_data()
        print dir1.get_node('dir2').get_node('file2').read_data()
	print

    #Using Porcelain
    #Initiating a new repo
    repo = porcelain.init("myrepo")


    #cloning a repo from a server
    porcelain.clone("https://github.com/sugarlabs/browse-activity.git","browse_activity_clone")


    #local cloning
    porcelain.clone("/home/vikram/browse_activity_clone","browse_activity_clone_1")
    print
    print "Commiting"
    open("myrepo/testfile","w").write("data")
    porcelain.add(repo,"myrepo/testfile")
    porcelain.commit(repo,"A sample commit")

    open("myrepo/testfile","w").write("data1")
    porcelain.add(repo,"myrepo/testfile")
    porcelain.commit(repo,"Second commit")

    open("myrepo/testfile1","w").write("sugar-labs")
    porcelain.add(repo,"myrepo/testfile1")
    porcelain.commit(repo,"First commit")
    
    print "Commit Logs:"
    print porcelain.log(repo)
Exemple #12
0
 def log(self, page):
     """ return revisions and dates of a given file as [(githash, date, author)]"""
     # The path seems to be picky here - wants not abspath but relative to os_git.
     relpath = os.path.relpath(page.abspath, os_git)
     buffer = StringIO.StringIO()
     porcelain.log(os_git, paths=[relpath], outstream=buffer)
     logstring = buffer.getvalue()
     print_debug('  dulwich git log for {} is {}'.format(
         page.abspath, logstring))
     return parse_porcelain_log(buffer.getvalue())
Exemple #13
0
 def log_action(self,sender):
     import StringIO
     s=StringIO.StringIO()
     w=ui.WebView(frame=self.view.frame)
     w.name='Log'
     porcelain.log(self._repo().path, outstream=s)
     log=s.getvalue()
     log=log.replace('\n','<p>')
     #print log
     w.load_html(log)
     w.present('popover')
Exemple #14
0
 def log_action(self, sender):
     import StringIO
     s = StringIO.StringIO()
     w = ui.WebView(frame=self.view.frame)
     w.name = 'Log'
     porcelain.log(self._repo().path, outstream=s)
     log = s.getvalue()
     log = log.replace('\n', '<p>')
     #print log
     w.load_html(log)
     w.present('popover')
Exemple #15
0
    def run(self, args):
        parser = optparse.OptionParser()
        parser.add_option("--reverse", dest="reverse", action="store_true",
                          help="Reverse order in which entries are printed")
        parser.add_option("--name-status", dest="name_status",
                          action="store_true",
                          help="Print name/status for each changed file")
        options, args = parser.parse_args(args)

        porcelain.log(".", paths=args, reverse=options.reverse,
                      name_status=options.name_status,
                      outstream=sys.stdout)
Exemple #16
0
    def log_action(self, sender):
        import io

        s = io.StringIO()
        w = ui.WebView(frame=self.view.frame)
        w.name = "Log"
        porcelain.log(self._repo().path, outstream=s)
        log = s.getvalue()
        log = log.replace("\n", "<p>")
        # print log
        w.load_html(log)
        w.present("popover")
def get_commits_for_all_repos(out):
    """Get commits as strings for all repos."""
    names_of_repos = next(os.walk(out))[1]
    commits = []

    for repo in names_of_repos:
        new_outstream = StringIO()
        repository = Repo(repo)
        with redirect_stdout(new_outstream):
            porcelain.log(repository, outstream=new_outstream)

        commits.append(new_outstream.getvalue())

    return commits
Exemple #18
0
def git_log(args):
    parser = argparse.ArgumentParser(description="git log arg parser")
    parser.add_argument("-f", "--format", action="store", dest="format", default=False)
    parser.add_argument(
        "-o", "--output", action="store", dest="output", type=argparse.FileType("w"), default=sys.stdout
    )

    parser.add_argument("-l", "--length", action="store", type=int, dest="max_entries", default=None)

    results = parser.parse_args(args)

    try:
        repo = _get_repo()
        porcelain.log(repo.repo.path, max_entries=results.max_entries, outstream=results.output)
    except ValueError:
        print command_help["log"]
Exemple #19
0
def get_git_contributors(project_dir=None):
    """从项目目录下的.git文件获取贡献者的信息"""
    try:
        if project_dir is None:
            project_dir = os.getcwd()
        commit_info = StringIO()
        porcelain.log(project_dir, outstream=commit_info, max_entries=100)
        commit_text = commit_info.getvalue()
        author_re = re.compile(r".*?Author:\s(.*?)\s<,*?")
        names = set()
        for line in commit_text.splitlines():
            match = re.findall(author_re, line)
            if match:
                names.add(match[0])
        return list(names)

    except Exception as e:
        warnings.warn("get_git_contributors error {0}".format(e))
	def commit_logs(self):
		try:
			if os.path.exists(self.repo_path):
				a = p.log(self.repo)
				return a
			else:
				return "Repo does not exist"
		except:
			return "No commits yet"
    def get_version(self):
        last_log = StringIO()

        # Get current branch
        current_branch = self.repo.refs.follow(b"HEAD")[0][1].decode().split("/")[-1]

        # Get last commit
        porcelain.log(self.repo, outstream=last_log, max_entries=1)

        commit_msg = last_log.getvalue()

        commit_match = re.search('commit: (.+?)\n', commit_msg)
        commit = commit_match.group(1) if commit_match else ""

        commit_match = re.search('Date: (.+?)\n\n', commit_msg)
        commit_date = commit_match.group(1).strip() if commit_match else ""

        commit_match = re.search("\n\n(.+?)\Z", commit_msg, flags=re.DOTALL)
        commit_info = commit_match.group(1).strip() if commit_match else ""

        return "I'm running commit `{}` of branch `{}`\n\n*{}*```{}```".format(commit, current_branch, commit_date, commit_info)
Exemple #22
0
 def _log(self, workspace=None):
     outstream = StringIO()
     porcelain.log(repo=self.workspace.working_dir, outstream=outstream)
     return ''.join(outstream.getvalue()).encode(), b''
Exemple #23
0
def git_log(args):
    parser = argparse.ArgumentParser(description='git log arg parser')
    parser.add_argument('-f',
                        '--format',
                        action='store',
                        dest='format',
                        default=False)
    parser.add_argument('-o',
                        '--output',
                        action='store',
                        dest='output',
                        type=argparse.FileType('w'),
                        default=sys.stdout)

    parser.add_argument('-l',
                        '--length',
                        action='store',
                        type=int,
                        dest='max_entries',
                        default=None)

    parser.add_argument('--oneline',
                        action='store_true',
                        dest='oneline',
                        default=False)

    results = parser.parse_args(args)

    try:
        repo = _get_repo()
        outstream = StringIO()
        porcelain.log(repo.repo.path,
                      max_entries=results.max_entries,
                      outstream=outstream)

        if not results.oneline:
            print(outstream.getvalue())
        else:

            last_commit = ''
            last_printed = ''
            start_message = False
            for line in outstream.getvalue().split('\n'):
                if line.startswith('commit:'):
                    tokens = line.split(' ')
                    last_commit = tokens[-1][:7]

                elif line.startswith('-------------'):
                    last_commit = ''
                    start_message = False

                elif line == '' and start_message is False:
                    start_message = True

                elif last_commit == last_printed and start_message is True:
                    continue

                elif start_message is True and not line.startswith(
                        '---------'):
                    print('{} {}'.format(last_commit, line))
                    last_printed = last_commit
                    start_message = False

    except ValueError:
        print(command_help['log'])
Exemple #24
0
    with open(pkg_init, 'w') as init:
        init.write('"""\nThis is the %s package.\n"""\n' % project_pkg)
        init.write(INIT_CONTENT % (args.author, args.email))
    LOGGER.info('Package file created: %s.', pkg_init)
    if args.git:
        repo = porcelain.init(project_name)
        LOGGER.info('Project Git repository initialized: %s.', repo)
        porcelain.add(repo, os.path.relpath(pkg_init, project_name))
        LOGGER.info('Project package added to index')
        # if global git config username and email not set, use args if specified
        kwargs = {}
        if not username:
            username = args.author
        if not useremail:
            useremail = args.email
        if not os.path.exists(GIT_GLOBAL):
            conf = repo.get_config()
            conf.set('user', 'name', username)
            conf.set('user', 'email', useremail)
            conf.write_to_path()
        else:
            kwargs['author'] = '%s <%s>' % (username, useremail)
        sha1 = porcelain.commit(repo, message='initial dump', **kwargs)
        LOGGER.info('Project initial commit: %s.', sha1)
        porcelain.log(repo, outstream=logging.root.handlers[0].stream)
    # make project layer folders
    for fp in args.folders:
        os.mkdir(os.path.join(project_name, project_pkg, fp))
        LOGGER.info('created folder: %s', fp)
    LOGGER.info('Carousel quickstart completed.')
# pip3 instal dulwich

from dulwich.repo import Repo
from dulwich import porcelain

r = Repo(".")
c = r[r.head()]
c.message
porcelain.log(".", max_entries=1)

# pip install dulwich


# pip install mistune
# pip install pyyaml
# pip install edn_format
# pip install toml
# pip install csvkit
# pip install xmltodict


# pip install records


# pip install Click

# pip install ptpython

# pip install sh

# pip install jrnl
Exemple #26
0
        """
        def log(repo='.', paths=None, outstream=sys.stdout, max_entries=None, reverse=False, name_status=False):
        Write commit logs.
        Parameters	repo	Path to repository
        paths	Optional set of specific paths to print entries for
        outstream	Stream to write log output to
        reverse	Reverse order in which entries are printed
        name_status	Print name status
        max_entries	Optional maximum number of entries to display
        """
        print >> sys.stderr, "handle command log"
        #print "log"
        #porcelain.log(repoPath)
        temp = tempfile.TemporaryFile(prefix='tmp_')
        print >> sys.stderr, temp.name
        porcelain.log(repoPath, outstream=temp)

        temp.seek(0, 0)
        content = temp.readlines()
        #print >> sys.stderr, content
        results = []
        commits = []
        parseCommit(content)
        splunk.Intersplunk.outputResults(commits)
        """
        for commit in commits:
            results.append(commit)
        results = []
        result = {}
        result["log"] = content
        results.append(result)
Exemple #27
0
 def _log(self, workspace=None):
     outstream = StringIO()
     porcelain.log(repo=self.workspace.working_dir, outstream=outstream)
     return ''.join(outstream.getvalue()).encode(), b''
Exemple #28
0
def git_log(args):
    parser = argparse.ArgumentParser(description='git log arg parser')
    parser.add_argument('-f','--format',
                        action='store',
                        dest='format',
                        default=False)
    parser.add_argument('-o','--output',
                        action='store',
                        dest='output',
                        type=argparse.FileType('w'),
                        default=sys.stdout)

    parser.add_argument('-l','--length',
                        action='store',
                        type=int,
                        dest='max_entries',
                        default=None)

    parser.add_argument('--oneline',
                        action='store_true',
                        dest='oneline',
                        default=False)
                        
    results = parser.parse_args(args)

    try:
        repo = _get_repo()
        outstream = StringIO()
        porcelain.log(repo.repo.path, max_entries=results.max_entries,outstream=outstream)
        
        if not results.oneline:
            print(outstream.getvalue())
        else:

            last_commit = ''
            last_printed = ''
            start_message = False
            for line in outstream.getvalue().split('\n'):
                if line.startswith('commit:'):
                    tokens = line.split(' ')
                    last_commit = tokens[-1][:7]
        
                elif line.startswith('-------------'):
                    last_commit = ''
                    start_message = False
                        
                elif line == '' and start_message is False:
                    start_message = True
                
                elif last_commit == last_printed and start_message is True:
                    continue 
                    
                elif start_message is True and not line.startswith('---------'):
                    print('{} {}'.format(last_commit, line))
                    last_printed = last_commit
                    start_message = False
                                      
                    
                    
    except ValueError:
        print(command_help['log'])